子节点中的XSL父节点数据

时间:2015-07-24 12:24:21

标签: node.js xml xslt xsd

源XML:

*

XSLT:

<COVER_DETAIL>
    <COVERDETAILS>
        <COVERNAME>AAA</COVERNAME>
        <EFFECTIVEDATE>2010-04-30</EFFECTIVEDATE>
        <EXPIRYDATE>2022-03-31</EXPIRYDATE>
        <COVERAMOUNT/>
        <COVERPERCENT/>
        <COVERCODE>60</COVERCODE>
    </COVERDETAILS>
    <COVERDETAILS>
        <COVERNAME>BBB</COVERNAME>
        <EFFECTIVEDATE>2010-04-30</EFFECTIVEDATE>
        <EXPIRYDATE>2022-03-31</EXPIRYDATE>
        <COVERAMOUNT/>
        <COVERPERCENT/>
        <COVERCODE>60</COVERCODE>
    </COVERDETAILS>
    <COVERDETAILS>
        <COVERNAME>CCC</COVERNAME>
        <EFFECTIVEDATE>2022-04-01</EFFECTIVEDATE>
        <EXPIRYDATE>2032-03-31</EXPIRYDATE>
        <COVERAMOUNT/>
        <COVERPERCENT>100</COVERPERCENT>
        <COVERCODE>62</COVERCODE>
    </COVERDETAILS>
    <COVERDETAILS>
        <COVERNAME>DDD</COVERNAME>
        <EFFECTIVEDATE>2022-04-01</EFFECTIVEDATE>
        <EXPIRYDATE>2032-03-31</EXPIRYDATE>
        <COVERAMOUNT/>
        <COVERPERCENT/>
        <COVERCODE>85</COVERCODE>
    </COVERDETAILS>
</COVER_DETAIL>

如何将<xsl:template name="COVERDETAILS"> <xsl:variable name="i" select="position()" /> <fo:table-row> <fo:table-cell> <fo:block> <xsl:value-of select="$i"/> <xsl:text>. </xsl:text> <xsl:value-of select="COVERNAME"/> </fo:block> </fo:table-cell> <fo:table-cell> <fo:block> --- Here i want to display percentage </fo:block> </fo:table-cell> </fo:table-row> </xsl:template> coverpercent的{​​{1}}值应用于每个模板的所有其他封面的covercode值。我希望将62 coverpercent封面与coverpecent covercode应用于每个封面。

1 个答案:

答案 0 :(得分:1)

您可以将变量定义为:

<xsl:variable name="perc" select="/COVER_DETAIL/COVERDETAILS[COVERCODE='62']/COVERPERCENT" />

然后在模板中使用此变量,您希望在其中显示百分比:

<xsl:value-of select="$perc"/>