Y
Yereth
Hi again,
still working on my xslt program and I ran into another problem. There is a
file which a contains the following structure:
<key>1</key>
<dict>
...
</dict>
<key>2</key>
<dict>
..
</dict>
When I am in a "dict" tag I want to get the value from the key before it,
because they belong to eachother.. (don't ask me why it's constructed like
this, wasn't my work) Now I wrote the following code which should do the
job:
<xsl:template match="plist/dict">
<xsl:element name="playlist">
<xsl:for-each select="child::dict/dict">
<xsl:call-template name="track"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template name="track">
<xsl:element name="track">
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select="preceding-sibling::key[position()=$pos]"/>
<xsl:for-each select="child::key">
<xsl:call-template name="key_value"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
Only, once pos has gained a value, it doesn't seem to get a new value in the
next round of the "for-each" loop.. is this a bug or am I making a mistake
in my thinking? Any help would be appreciated!
Thanks in advance,
Yereth
still working on my xslt program and I ran into another problem. There is a
file which a contains the following structure:
<key>1</key>
<dict>
...
</dict>
<key>2</key>
<dict>
..
</dict>
When I am in a "dict" tag I want to get the value from the key before it,
because they belong to eachother.. (don't ask me why it's constructed like
this, wasn't my work) Now I wrote the following code which should do the
job:
<xsl:template match="plist/dict">
<xsl:element name="playlist">
<xsl:for-each select="child::dict/dict">
<xsl:call-template name="track"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
<xsl:template name="track">
<xsl:element name="track">
<xsl:variable name="pos" select="position()"/>
<xsl:apply-templates select="preceding-sibling::key[position()=$pos]"/>
<xsl:for-each select="child::key">
<xsl:call-template name="key_value"/>
</xsl:for-each>
</xsl:element>
</xsl:template>
Only, once pos has gained a value, it doesn't seem to get a new value in the
next round of the "for-each" loop.. is this a bug or am I making a mistake
in my thinking? Any help would be appreciated!
Thanks in advance,
Yereth