Hallo,
Wenn du nicht willst, dass das Template für alle Intervalle gilt, sage es doch dem Template: entweder durch:
<xsl:template match="/Intervall[1]"> oder besser durch:
<xsl:apply-templates select="Intervall[1]" />Also es soll für alle INtervalle gültig sein, heisst: Nachdem er jeden value durchgegangen ist hört auf. Mit deinem Vorschlag, geschieht zwar das es nur einmal alle durchgeht heist:
1*4 Intervall
dann
1*3 Intervalle
dann
1*2 Intervalle
dann
1*1IntervallOhne diese [1]
passiert dies4*4Intervalle
3*4 Intervalle
usw.
Verstehe ich nicht ganz:
<xsl:apply-templates select="Intervall"/>
dann führe ich das XSLT aus (im R habe ich den Wert vom Value hineingeschreiben um zu sehen/zeigen was gerade abgearbeitet wurde), ausgabe (hier etwas verkürtzt)
<line x1="5.625%" y1="82.6086956521739%" x2="11.25%" y2="78.26086956521739%" R="100"/>
<line x1="11.25%" y1="78.26086956521739%" x2="16.875%" y2="73.91304347826087%" R="105"/>
<line x1="16.875%" y1="73.91304347826087%" x2="22.5%" y2="69.56521739130434%" R="110"/>
<line x1="22.5%" y1="69.56521739130434%" x2="28.125%" y2="65.21739130434783%" R="115"/>
<line x1="28.125%" y1="65.21739130434783%" x2="33.75%" y2="60.869565217391305%" R="120"/>
<line x1="33.75%" y1="60.869565217391305%" x2="39.375%" y2="56.52173913043478%" R="125"/>
<line x1="39.375%" y1="56.52173913043478%" x2="45%" y2="52.173913043478265%" R="130"/>
<line x1="45%" y1="52.173913043478265%" x2="50.625%" y2="47.82608695652174%" R="135"/>
<line x1="50.625%" y1="47.82608695652174%" x2="56.25%" y2="43.47826086956522%" R="140"/>
<line x1="56.25%" y1="43.47826086956522%" x2="61.875%" y2="39.130434782608695%" R="145"/>
<line x1="61.875%" y1="39.130434782608695%" x2="67.5%" y2="34.78260869565217%" R="150"/>
<line x1="67.5%" y1="34.78260869565217%" x2="73.125%" y2="30.434782608695656%" R="155"/>
<line x1="73.125%" y1="30.434782608695656%" x2="78.75%" y2="26.086956521739125%" R="160"/>
<line x1="78.75%" y1="26.086956521739125%" x2="84.375%" y2="21.73913043478261%" R="165"/>
<line x1="84.375%" y1="21.73913043478261%" x2="90%" y2="17.391304347826093%" R="170"/>
bis dahin ist alles OK.
Jetzt sehe ich einen Fehler, als <Intervall name="30.05.2006"><value>175</value> erreicht ist.
Das Template wurde aufgerufen, $knoten ist jetzt eben "<value>175</value>". Hier trifft xsl:when nicht, denn es gibt keinen "following-sibling::value", also geht es in xsl:otherwise hinein, die xs:if trifft auch nicht zu, denn es gibt auch keinen "parent::Intervall/following-sibling::Intervall" also es wird hier kein <line> erzeugt!
Das sollten wir also zuerst beheben.
<xsl:otherwise>
<xsl:if test="(parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1])">
<line x1="{$add}%" y1="{100-(((.) - $MinV)*(100 div $Delta))}%" x2="{$add+$add.GRAPH}%" y2="{100-(((parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1]) - $MinV)*(100 div ($MaxV - $MinV)))}%"/>
</xsl:if>
<xsl:if test="not(parent::Intervall/following-sibling::Intervall)">
<line x1="{$add}%" y1="{100-(((.) - $MinV)*(100 div $Delta))}%" x2="{$add+$add.GRAPH}%" y2=" HIER FEHLT JETZT DER WERT!"/>
</xsl:if>
Führen wir die Transformation erneut aus, kommt jetzt alles richtig:
<line x1="84.375%" y1="21.73913043478261%" x2="90%" y2="17.391304347826093%" R="170"/>
<line x1="90%" y1="17.391304347826093%" x2="95.625%" y2="" R="175"/>
bis eben auf y2 für das letzte <line>.
Wenn ich dich richtig verstehe sollte es hier dann auch Schluß sein mit der Transformation?
Dann verschieben wir xsl:call-template:
<xsl:template match="value" name="Temp1">
<xsl:param name="add" select="$add.GRAPH"/>
<xsl:param name="knoten" select="."/>
<xsl:for-each select="$knoten/descendant-or-self::value">
<xsl:choose>
<xsl:when test="following-sibling::value[position() = 1]">
<line x1="{$add}%" y1="{100-(((.) - $MinV)*(100 div ($MaxV - $MinV)))}%" x2="{$add+$add.GRAPH}%" y2="{100-(((following-sibling::value[position() = 1]) - $MinV)*(100 div ($MaxV - $MinV)))}%" R="{.}"/>
<xsl:call-template name="Temp1">
<xsl:with-param name="add" select="$add+$add.GRAPH"/>
<xsl:with-param name="knoten" select="following-sibling::value[position() = 1]"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:if test="(parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1])">
<line x1="{$add}%" y1="{100-(((.) - $MinV)*(100 div $Delta))}%" x2="{$add+$add.GRAPH}%" y2="{100-(((parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1]) - $MinV)*(100 div ($MaxV - $MinV)))}%" R="{.}"/>
<xsl:call-template name="Temp1">
<xsl:with-param name="add" select="$add+$add.GRAPH"/>
<xsl:with-param name="knoten" select="parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1]"/>
</xsl:call-template>
</xsl:if>
<xsl:if test="not(parent::Intervall/following-sibling::Intervall)">
<line x1="{$add}%" y1="{100-(((.) - $MinV)*(100 div $Delta))}%" x2="{$add+$add.GRAPH}%" y2="{100-(((parent::Intervall/following-sibling::Intervall[position() = 1]/value[position() = 1]) - $MinV)*(100 div ($MaxV - $MinV)))}%" R="{.}"/>
</xsl:if>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:template>
Und auch das xsl:apply-templates müssen wir ändern:
<xsl:apply-templates select="Intervall[1]/value[1]"/>
Da im Template immer wieder auf Folgeknoten von value zugegriffen wird, und diese dann auch ins Template geholt werden, brauchen wir nur Intervall[1]/value[1] um die gewünschte ausgabe zu erzeugen.
Auf $countInt" kann man komplett verzichten.
Ich hoffe das Hilft!
Grüße
Thomas