这是我的XML-
<CATALOG> <NAME>C1</NAME> <CD> <NAME>Empire Burlesque</NAME> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <NAME>Hide your heart</NAME> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG>
我想将目录中的NAME标签替换为CATALOG-NAME,将CD中的NAME标签替换为CD-NAME,这应该使我的xml看起来像这样,
<CATALOG> <CATALOG-NAME>C1</CATALOG-NAME> <CD> <CD-NAME>Empire Burlesque</CD-NAME> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <CD-NAME>Hide your heart</CD-NAME> <ARTIST>Bonnie Tyler</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG>
对要重命名的元素使用带有覆盖的标识变换:
原文链接:https://www.f2er.com/xml/292974.html<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()" /> </xsl:copy> </xsl:template> <xsl:template match="CD/NAME"> <CD-NAME><xsl:apply-templates select="@*|node()" /></CD-NAME> </xsl:template> <xsl:template match="CATALOG/NAME"> <CATALOG-NAME><xsl:apply-templates select="@*|node()" /></CATALOG-NAME> </xsl:template> </xsl:stylesheet>