Ich lerne gerade XSL und habe eine Frage bezüglich der Querverweise. Mein Ziel XML-Datei ist wie folgt aufgebaut:XSL-Querverweis
<XML>
<Model>
<packedElement typ="class" id="1"/>
<packedElement typ="class" id="2"/>
<packedElement typ="class" id="3"/>
</Model>
<Elements>
<Element idref="1">
<Attributes comment="comment 1."/>
</Element>
<Element idref="2">
<Attributes comment="comment 2."/>
</Element>
<Element idref="3">
<Attributes comment="comment 3."/>
</Element>
</Elements>
</XML>
I id = idref verbinden möchten. Mein Ziel ist es, alle packedElements aufzulisten und ihren Kommentar zu drucken. Kannst du mir helfen?
Ich habe versucht, es mit der Schlüssel-Funktion zu lösen, aber ich war nicht sehr erfolgreich.
Edit:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:key name="CommentK" match="Element" use="@idref"/>
<xsl:template match="XML">
<XML>
<xsl:apply-templates/>
</XML>
</xsl:template>
<xsl:template name="Start" match="packedElement">
<xsl:variable name="TEST" select="@id"/>
<xsl:variable name="Comment">
<xsl:call-template name="FindComment">
<xsl:with-param name="test2" select="@id"/>
</xsl:call-template>
</xsl:variable>
<content comment="{$Comment}" id ="{@id}" test="{$TEST}"></content>
</xsl:template>
<xsl:template name="FindComment">
<xsl:param name="test2"/>
<xsl:for-each select="key('CommentK', '$test2')">
<xsl:value-of select="Attributes/@comment"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
XSLT-Version ist 2.0. (Btw kann mir jemand sagen, der Unterschied zwischen dem .xslt und .XSL?)
XSLT 1.0 oder 2.0? –
Wie sah dein Versuch aus? Wie soll das Ergebnis aussehen? – JLRishe
Ich denke, Ihr Versuch hätte fast funktioniert, außer dass Sie "$ test2" verwendet haben, was der _string-Wert "$ test2" ist. Es sollte nur 'key ('CommentK', $ test2)' 'sein. Ich denke jedoch, dass 'FindComment' und' for-each' zu viel sind. Martin Honnens Antwort ist eine gute. – JLRishe