Hallo!
Ich lerne gerade anhand des w3school-Beispiels XSLT.
Der XML-Code:
Mein XSLT 2.0-Code
Output:
Wieso wird da nicht der Titel der ersten CD angezeigt?
So wie ich es verstehe, steht das erste
für
und bildet den Kontext für das
, d.h. das
sollte als
interpretiert werden.
Dann sollte der prozessor das template für
finden und dann relativ dazu den
auswählen, sodass die gesamte Query folgendermaßen lautet:
.
Wieso funktioniert das nicht?
Ich lerne gerade anhand des w3school-Beispiels XSLT.
Der XML-Code:
Code:
<?xml version="1.0" encoding="UTF-8"?> <!-- Edited by XMLSpy --> <catalog> <cd> <title>Empire Burlesque</title> <artist>Bob Dylan</artist> <country>USA</country> <company>Columbia</company> <price>10.90</price> <year>1985</year> </cd> usw... </catalog>
Code:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:err="http://www.w3.org/2005/xqt-errors" version="2.0" exclude-result-prefixes="xs xdt err fn"> <xsl:template match="/"> <html> <body> <h2>My CD Collection</h2> <xsl:apply-templates select="cd[1]"/> </body> </html> </xsl:template> <xsl:template match="cd[1]"> <p> <span><xsl:value-of select="title"/></span> </p> </xsl:template> </xsl:stylesheet>
Code:
<html> <body> <h2>My CD Collection</h2> </body> </html>
So wie ich es verstehe, steht das erste
Code:
template match="/"
Code:
<catalog>
Code:
template match="cd[1]"
Code:
template match="cd[1]"
Code:
match="catalog/cd[1]"
Dann sollte der prozessor das template für
Code:
cd[1]
Code:
title
Code:
catalog/cd[1]/title
Wieso funktioniert das nicht?
Comment