【发布时间】:2019-05-24 07:23:25
【问题描述】:
我有一个在 2 个不同级别中具有相同元素的 xml,我需要比较 2 个级别中元素的值并返回匹配元素的值。例如我有以下 xml
<root>
<profiles>
<profile>
<Name>xxx</Name>
<Gender>Male</Gender>
</profile>
<profile>
<Name>yyy</Name>
<Gender>Female</Gender>
</profile>
</profiles>
<subroot>
<profiles>
<profile>
<sName>xxx</sName>
<sAge>10</sAge>
</profile>
<profile>
<sName>yyy</sName>
<sAge>20</sAge>
</profile>
</profiles>
</subroot>
</root>
我需要为//root/subroot/profiles/profile 放置循环并获取Name,Age,Gender 元素的值。而我们必须通过将 name 元素值与 xpath //root/profiles/profile 进行比较来获取 Gender 元素的值。当我使用下面的代码时
<xsl:for-each select="//root/subroot/profiles/profile">
<xsl-for-each select="//root/profiles/profile">
<xsl:choose>
<xsl:when name=sname>
<xsl:value-of select="Gender">
</xsl:when>
</xsl:choose>
<xsl:for-each>
</xsl-for-each>
当循环遍历第二个元素时,我得到了第一个元素的相应性别值,返回的第一个元素的相同值对于 xxx,yyy 都返回为“男性”。有人检查此代码并让我知道此问题的任何解决方法
【问题讨论】:
标签: xslt xslt-1.0 xslt-2.0 xslt-grouping xslt-3.0