给出一个xml树示例:
<root>
<child></child>
<child>
<child></child>
</child>
</root>有没有人能帮我写一个样式表,用来添加id和parentid属性:
<root id="1" parentID="">
<child id="2" parentID="1"></child>
<child id="3" parentID="1">
<child id="4" parentID="3"></child>
</child>
</root>发布于 2013-09-16 18:26:21
使用
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="*">
<xsl:copy>
<xsl:attribute name="id">
<xsl:apply-templates select="." mode="number"/>
</xsl:attribute>
<xsl:attribute name="parentId">
<xsl:apply-templates select="parent::*" mode="number"/>
</xsl:attribute>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*" mode="number">
<xsl:number level="any" count="*"/>
</xsl:template>
</xsl:stylesheet>https://stackoverflow.com/questions/18824863
复制相似问题