我需要创建一个能够读取两个 xml 文件的 xsl,这两个文件除了第一个标记外具有相同的结构:
入站 xml:
<beans:beans> <fix-inbound> <message></message> </fix-inbound> </beans:beans>
出站 xml:
<beans:beans> <fix-outbound> <message></message> </fix-outbound> </beans:beans>
我能找到的解决方案是:
- 创建两个文件来读取入站和出站
如果喜欢的话会很糟糕:
<xsl:if test="fix-inbound"> code to read the content </xsl:if> <xsl:if test="fix-outbound"> same piece of code to read the content </xsl:if>
在我的
<xsl:for-each select="$valueOfMyFirstTag">
中使用一个变量其中变量的值可以是 fix-inbound 或 fix-outbound
但是,我不知道如何获取第一个标签的值。可以使用 xsl 吗?
有没有更优雅的方法来解决这个问题?
最佳答案
你可以使用
<xsl:for-each select="/*/fix-inbound | /*/fix-outbound">
(或者根据您的用例,使用 apply-templates
而不是 for-each
)。
关于xml - 如何用xsl区分两个相似的标签(变量),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5795504/