[英]How to add specific attribute to every node in Xml file using Xsl?
我有一些看起來像這樣的Xml:
<books>
<book id="1">
<name>My book</name>
<author>My author</author>
</book>
<book id="2">
<name>My other book</name>
<author>My other author</author>
</book>
</books>
我希望它看起來像:
<books>
<book id="1">
<name id="1">My book</name>
<author id="1">My author</author>
</book>
<book id="2">
<name id="2">My other book</name>
<author id="2">My other author</author>
</book>
</books>
有人能指出我正確的方向嗎?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--Standard identity template that copies all content -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--special template for elements who's parent has an @id -->
<xsl:template match="*[../@id]">
<xsl:copy>
<xsl:copy-of select="../@id" />
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.