且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在 XSLT 中使用 for 循环并根据迭代获取节点值

更新时间:2023-01-16 16:48:40

我在您尝试的 XSLT 中找不到任何押韵或原因.可以通过以下方式非常简单地实现预期结果:

I cannot find any rhyme or reason in your attempted XSLT. The expected result can be achieved very simply by:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wd="urn:com.workday/bsvc">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:strip-space elements="*"/>

<xsl:template match="wd:Report_Entry">
    <xsl:variable name="common">
        <xsl:value-of select="wd:Employee_ID" />
        <xsl:text>, </xsl:text>
        <xsl:value-of select="wd:Worker" />
        <xsl:text>, </xsl:text>
        <xsl:value-of select="wd:Employee_Last_Name" />
        <xsl:text>, </xsl:text>
        <xsl:value-of select="wd:Employee_First_Name" />
        <xsl:text>, </xsl:text>
    </xsl:variable> 
    <xsl:for-each select="wd:COBRA_Records_within_Range">
        <xsl:copy-of select="$common"/>
        <xsl:value-of select="wd:Qualifying_Event_Date" />
        <xsl:text>, </xsl:text>
        <xsl:value-of select="wd:Eligibility_Reason" />
        <xsl:text>, </xsl:text>
        <xsl:value-of select="wd:Benefit_Plan1" />
        <xsl:text>&#10;</xsl:text>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>