This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: AW: XSL equivalent to SQL "unique"
- To: Oliver Becker <obecker at informatik dot hu-berlin dot de>
- Subject: Re: AW: [xsl] XSL equivalent to SQL "unique"
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Wed, 18 Apr 2001 16:33:14 +0100
- CC: xsl-list at lists dot mulberrytech dot com, "Nestel, Frank" <frank dot nestel at coi dot de>
- Organization: Jeni Tennison Consulting Ltd
- References: <200104180942.LAA32278@mail.informatik.hu-berlin.de>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Oliver,
> Perhaps Jeni will have a break and post some explanations on how to
> solve problems like yours ;-)
Well, I'm on a break, but what could I possibly add to the solution
that you gave?
Only, I guess, that this is an example of a difficult grouping problem
where really you want to reuse the information about the *sorted*
unique values, rather than having to sort them again for every row.
This is one of those times that the node-set() extension function
really comes into its own. So you could declare a top-level $cols
variable with:
<xsl:variable name="cols-rtf">
<!-- get the uniquely named child elements of the set elements -->
<xsl:for-each select="//set/*[count(.|key('cols',name())[1]) = 1]">
<!-- sort the child elements by their name -->
<xsl:sort select="name()" />
<!-- create col elements to hold that information -->
<col name="{name()}" />
</xsl:for-each>
</xsl:variable>
<!-- turn $cols-rtf into a node set with an extension function
(substitute prefix of your chosen processor) -->
<xsl:variable name="cols" select="exsl:node-set($cols-rtf)" />
With that, then the various xsl:for-eaches for generating the column
headers and the row data don't have to sort, they can just use the
$cols variable and the name attribute from it, e.g.
<xsl:template match="set">
<tr>
<th><xsl:value-of select="@name" /></th>
<xsl:variable name="entries" select="*" />
<xsl:for-each select="$cols">
<td>
<xsl:value-of select="$entries[name() = current()/@name]" />
</td>
</xsl:for-each>
</tr>
</xsl:template>
Of course this isn't portable. So roll on XSLT 2.0... or support for
EXSLT ;)
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list