[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: AW: XSL equivalent to SQL "unique"

Subject: Re: AW: XSL equivalent to SQL "unique"
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Wed, 18 Apr 2001 16:33:14 +0100
sql unique sort
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.