B
Brian Schroeder
Hello Group,
I'm quite new to xml, xpath and xslt so I hope I've not overlooked a
resource where the answer to my question is.
I'll try to give a short example, but in XML everything gets bloated
really fast.
I've got the following situation:
=== a.xml ===
<?xml version="1.0" encoding="ISO-8859-1"?>
<n categorie="A">
<n categorie="B">
<n categorie="C"/>
</n>
<n categorie="D"/>
</n>
===
I want to transform this via xslt to the following
A
A->B
A->B->C
A->D
I came up with the following stylesheet
=== test.xsl ===
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="n">
<xsl:value-of select="ancestor::*[@categorie]/attribute::categorie"/>
-> <xsl:value-of select="@categorie"/><xsl:text>
</xsl:text>
<xsl:apply-templates select="n"/>
</xsl:template>
</xsl:stylesheet>
===
I guess, that "ancestor::*[@categorie]/attribute::categorie" should select
all ancestor, having an attribute categorie, and from those nodes the
attribute. My problem is, that only the first attribute "A" will result
from this question. It seems, that I have to concatenate the values, but
concat did not help.
I would really appreciate help and even more pointers to some online
resource where I can learn about this kind of things. (So far, the best I
found were the w3 recommendations. Most of the other stuff seemed quite
useless.)
Thanks a lot,
Brian
I'm quite new to xml, xpath and xslt so I hope I've not overlooked a
resource where the answer to my question is.
I'll try to give a short example, but in XML everything gets bloated
really fast.
I've got the following situation:
=== a.xml ===
<?xml version="1.0" encoding="ISO-8859-1"?>
<n categorie="A">
<n categorie="B">
<n categorie="C"/>
</n>
<n categorie="D"/>
</n>
===
I want to transform this via xslt to the following
A
A->B
A->B->C
A->D
I came up with the following stylesheet
=== test.xsl ===
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="n">
<xsl:value-of select="ancestor::*[@categorie]/attribute::categorie"/>
-> <xsl:value-of select="@categorie"/><xsl:text>
</xsl:text>
<xsl:apply-templates select="n"/>
</xsl:template>
</xsl:stylesheet>
===
I guess, that "ancestor::*[@categorie]/attribute::categorie" should select
all ancestor, having an attribute categorie, and from those nodes the
attribute. My problem is, that only the first attribute "A" will result
from this question. It seems, that I have to concatenate the values, but
concat did not help.
I would really appreciate help and even more pointers to some online
resource where I can learn about this kind of things. (So far, the best I
found were the w3 recommendations. Most of the other stuff seemed quite
useless.)
Thanks a lot,
Brian