Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml XSL转换:从变量按ID获取元素_Xml_Xslt - Fatal编程技术网

Xml XSL转换:从变量按ID获取元素

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"&

我正在解析包含不同元素的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:value-of select="role/@refId"/>
        </xsl:variable>

        <!-- This is the problematic part -->
        <xsl:value-of select="/root/roles/role[@id='$refId']"/>

        <xsl:text>&#10;</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:)我昨天确实遇到了这个问题,但找不到帮助我的答案。