Xml XSL转换:从变量按ID获取元素
我正在解析包含不同元素的XML文件以构建CSV。我反复访问像这样的人Xml XSL转换:从变量按ID获取元素,xml,xslt,Xml,Xslt,我正在解析包含不同元素的XML文件以构建CSV。我反复访问像这样的人 <xsl:template match="/root/persons/person"> <xsl:for-each select="."> <xsl:value-of select="name" /> <xsl:text>;</xsl:text> <xsl:variable name="refId"&
<xsl:template match="/root/persons/person">
<xsl:for-each select=".">
<xsl:value-of select="name" />
<xsl:text>;</xsl:text>
<xsl:variable name="refId">
<xsl:value-of select="role/@refId"/>
</xsl:variable>
<!-- This is the problematic part -->
<xsl:value-of select="/root/roles/role[@id='$refId']"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
;
在我的person元素中,我有一个refId,它引用角色元素的ID。如何将refId加载到上述变量中以获取角色名称?尝试使用以下方法:
<xsl:value-of select="/root/roles/role[@id=string($refId)]"/>
我假设您的路径是正确的,因为我们无法查看您的XML进行验证。@juergend your're welcome:)我昨天确实遇到了这个问题,但找不到帮助我的答案。