Meine XML ist 'input.xsl'Mein xslt produziert nicht korrekte Ausgabe?
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="input.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>
</catalog>
Jetzt möchte ich mit Hilfe von XSLT, wie folgend, (OUTPUT-Format)
<?xml version="1.0" encoding="ISO-8859-1"?>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
</cd>
</catalog>
Dafür ein anderes XML-Dokument unter Verwendung der obigen XML-Datei zu erzeugen, ich xsl-Datei ‚input.xsl‘
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:element name="catalog">
<xsl:apply-templates select="catalog/cd/title"/> <br/>
<xsl:apply-templates select="catalog/cd/artist"/>
</xsl:element>
</xsl:template>
<xsl:template match="catalog/cd/artist">
<xsl:element name="cd">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:template>
<xsl:template match="catalog/cd/title">
<xsl:element name="cd">
<xsl:value-of select="current()"/>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
die obige xsl-Datei erstellt nicht die Ausgabe im xML-Format erzeugen. Also, was ist das Problem in meinem Code. Führe mich. Danke im Voraus.
+1 Ja, ich denke, das das aktuelle Knoten Konzept auf eine hilfreiche Weise – PandaWood
Built-in der Regel für Text erklärt Knoten Ausgabe der Zeichenfolge Wert. Also sind alle Ihre Regeln die gleiche Regel ' xsl: template>'. Sie müssen jedoch die Abisolierregeln hinzufügen, da die integrierte Regel für Elemente (in diesem Fall "cd" chlidren andere als "title" oder "artist") Vorlagen auf untergeordnete Elemente anwenden. –