XML:
<Grandparent>
<Parent>
<Children>
<Info>
<Name>
<label id="chname"/>
</Name>
</Info>
</Children>
<Children>
<Info>
<Name>
<label id="chname"/>
</Name>
</Info>
</Children
<Children>
<Info>
<Name>
<label id="chname"/>
</Name>
</Info>
</Children
</Parent>
</Grandparent>
XSLT:
<xsl:template match"/">
<xsl:apply-templates select="GrandParent/Parent/Children" />
</xsl:template>
<xsl:template match="Children">
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<xsl:template match="Children/Info/Name/label">
<xsl:copy>
<xsl:variable name="childCtr" select="Parent/Children[position()]"/>
<xsl:attribute name="text">
<xsl:value-of select="$childCtr"/>
</xsl:attribute>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>
<!--Identity template copies content forward -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
如何在将属性添加到标签标签并获取整个“孩子”节点时使用模板获取“孩子”的索引或位置?
像:
Parent[0] = Children1,
Parent[1] = Children2,
Parent[2] = Children3
我怎么能得到这种东西?我需要帮助。提前致谢