我想将 XML 转换为其他格式的 XML,所以我使用了 XSLT。但是tt变成了不好的结果。
XML:
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
<cd>
<title>Greatest Hits</title>
<artist>Dolly Parton</artist>
<country>USA</country>
<company>RCA</company>
<price>9.90</price>
<year>1982</year>
</cd>
</catalog>
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" encoding="utf-8" indent="yes" />
<xsl:template match="/">
<root>
<items>
<xsl:for-each select="catalog/cd">
<item>
<xsl:value-of select="artist"/>
</item>
</xsl:for-each>
</items>
</root>
</xsl:template>
</xsl:stylesheet>
我想要的结果(在浏览器中):
<?xml version="1.0" encoding="utf-8"?>
<root>
<items>
<item>Empire Burlesque</item>
<item>Hide your heart</item>
<item>Greatest Hits</item>
</items>
</root>
实际结果(在浏览器中):
Empire Burlesque Hide your heart Greatest Hits
我的 XSLT 有什么问题?