我无法从我的 xml 获取 xsl 编码子循环中的根节点数据

I am not able to get the root node data in the child loop in xsl coding from my xml

xsl编码中如何在子循环中获取根节点数据 您能否说明如何在我的子循环中获取根节点数据。 或者除了下面还有其他方法吗?感谢你的帮助。 我的XML

<wd:Report_Data xmlns:wd="urn:com.workday.report/INT_Outbound">
    <wd:Report_Entry>
        <wd:Employee_ID>12345</wd:Employee_ID>
        <wd:LastName>Raj</wd:LastName>
        <wd:FirstName>Kiran</wd:FirstName>
        <wd:Dependents>
            <wd:Dependent_ID>D1245</wd:Dependent_ID>
            <wd:Dep_FirstName>Mahi</wd:Dep_FirstName>
            <wd:Spouse_LastName>Raj</wd:Spouse_LastName>
        </wd:Dependents>
        <wd:Dependents>
            <wd:Dependent_ID>D1256</wd:Dependent_ID>
            <wd:Dep_FirstName>Praveen</wd:Dep_FirstName>
            <wd:Spouse_LastName>Raj</wd:Spouse_LastName>
        </wd:Dependents>
        <wd:Benefits>
            <wd:Coverage>EE + Family</wd:Coverage>
        </wd:Benefits>
    </wd:Report_Entry>
</wd:Report_Data>

我的 XSL 代码

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:wd="urn:com.workday.report/INT_Outbound" version="2.0">

    <xsl:output method="text" indent="no"/> 
    <xsl:strip-space elements="*"/>

        <xsl:variable name="NEWLINE" select="'&#xa;'"/>
        <xsl:variable name="COMMA" select="','"/>
        
    <xsl:template match="/">    

    <xsl:for-each select="wd:Report_Data/wd:Report_Entry/wd:Dependents">
    
            <xsl:value-of select="concat(wd:Report_Data/wd:Employee_ID,$COMMA)"/>           
            <xsl:value-of select="concat(wd:Report_Data/wd:LastName,$COMMA)"/>  
            <xsl:value-of select="concat(wd:Report_Data/wd:FirstName,$COMMA)"/>         
            
            <xsl:value-of select="concat(wd:Dependent_ID,$COMMA)"/> 
            <xsl:value-of select="concat(wd:Spouse_LastName,$COMMA)"/>              
            <xsl:value-of select="wd:Dep_FirstName"/>           
            
          <xsl:value-of select="$NEWLINE"/>
    
    </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

当前输出:

,,,D1245,Raj,Mahi
,,,D1256,Raj,Praveen

预期输出:

12345,Raj,Kiran,D1245,Raj,Mahi
12345,Raj,Kiran,D1246,Raj,Praveen

您的上下文已经是 wd:Report_Data/wd:Report_Entry/wd:Dependents,因此您需要返回到 wd:Report_Entry(使用 ..)才能获得这些值。

已更新 XSLT...

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
   xmlns:wd="urn:com.workday.report/INT_Outbound" version="2.0">

    <xsl:output method="text" indent="no"/> 
    <xsl:strip-space elements="*"/>

        <xsl:variable name="NEWLINE" select="'&#xa;'"/>
        <xsl:variable name="COMMA" select="','"/>
        
    <xsl:template match="/">    

    <xsl:for-each select="wd:Report_Data/wd:Report_Entry/wd:Dependents">
    
            <xsl:value-of select="concat(../wd:Employee_ID,$COMMA)"/>           
            <xsl:value-of select="concat(../wd:LastName,$COMMA)"/>  
            <xsl:value-of select="concat(../wd:FirstName,$COMMA)"/>         
            
            <xsl:value-of select="concat(wd:Dependent_ID,$COMMA)"/> 
            <xsl:value-of select="concat(wd:Spouse_LastName,$COMMA)"/>              
            <xsl:value-of select="wd:Dep_FirstName"/>           
            
          <xsl:value-of select="$NEWLINE"/>
    
    </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>

Fiddle: http://xsltfiddle.liberty-development.net/6q1SDk2