Folks,
I'm struggling with XSLT key's and stuff.... anybody out there who
*REALLY* understands this stuff???
Okay, my XML file looks something like this (partially):
<?xml version="1.0" encoding="ISO-8859-1"?>
<report>
<meta>
<structure>
<title seq="4" text="Foo" />
<title seq="5" text="Bar" />
<title seq="6" text="Widgets" />
<title seq="16" text="Foo" />
<title seq="17" text="Bar" />
</structure>
</meta>
</report>
What I'd like to achieve is to get a list of comma-separated values of
the "text" attribute, with each entry showing up only once, and
alphabetically sorted, something like:
Defined texts: Bar, Foo, Widgets
I tried to define a xsl:key that would help me achieve this - no luck
so far. I had a sample, but that was based on a XML element, rather
than an attribute - and I just can't seem to make the transition!
So here's my XSL definition of the key:
<xsl:key name="distinct" match="title" use="@text" />
so I was thinking this will keep a list of unique "text" attributes,
no?
I wanted to output the list from my XSL with this fragment:
<xsl:for-each
select="report/meta/structure/title[generate-id()=generate-id(key('distinct',
..))]">
<xsl:sort select="@title" />
<xsl:value-of select="@text">
<xsl:if test="position() != last()">, </xsl:if>
</xsl:for-each>
The extra clause in the xsl:for-each is the one I grabbed from a
sample, based on a XML element being used (rather than the attribute).
I just can't seem to make it work, no matter how I try to change
around the xsl:key and the xsl:for-each clauses.....
Any takers? It's probably really stupid, once you know how to do it -
but I just can't seem to crack this one!!
Any help is highly appreciated !!
Thanks
Marc
================================================== ==============
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch