Re: [xsl] Sorting and grouping unknown elements

Subject: Re: [xsl] Sorting and grouping unknown elements
From: "Claus Jessing" <claus@xxxxxxxxxx>
Date: Mon, 24 Sep 2007 08:53:01 +0200
Thanks David

Couldn't get your first example to work. I'm using javax.xml.transform
for the actual transformation and Eclipse tells me that for-each-group
is an unkown xsl element.

Your other example works just fine tho :-)

Thanks

Claus Jessing

On 9/21/07, David Carlisle <davidc@xxxxxxxxx> wrote:
>
>
> oops I grouped the wrong thing, try
>
> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>   <xsl:output indent="yes"/>
>   <xsl:template match="rowset">
>     <xsl:for-each-group select="row/*" group-by="name()">
>       <xsl:sort select="name()"/>
>       <select name="{current-grouping-key()}">
>         <xsl:for-each-group select="current-group()" group-by=".">
>           <xsl:sort/>
>           <option><xsl:value-of select="."/></option>
>         </xsl:for-each-group>
>       </select>
>     </xsl:for-each-group>
>   </xsl:template>
> </xsl:stylesheet>
>
> $ saxon8 rs.xml rs2.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <select name="color">
>    <option>Blue</option>
>    <option>Red</option>
> </select>
> <select name="make">
>    <option>Toyota</option>
> </select>
> <select name="model">
>    <option>Corolla</option>
>    <option>Yaris</option>
> </select>
>
>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
>   <xsl:output indent="yes"/>
>   <xsl:key  name="n" match="*" use="name()"/>
>   <xsl:key  name="v" match="*" use="concat(name(),.)"/>
>   <xsl:template match="rowset">
>     <xsl:for-each select="row/*[generate-id(.)=generate-id(key('n',name()))]">
>       <xsl:sort select="name()"/>
>       <select name="{name()}">
>         <xsl:for-each select="../../row/*[generate-id(.)=generate-id(key('v',concat(name(current()),.)))]">
>           <xsl:sort/>
>           <option><xsl:value-of select="."/></option>
>         </xsl:for-each>
>       </select>
>     </xsl:for-each>
>   </xsl:template>
> </xsl:stylesheet>
>
>
> $ saxon rs.xml rs1.xsl
> <?xml version="1.0" encoding="utf-8"?>
> <select name="color">
>    <option>Blue</option>
>    <option>Red</option>
> </select>
> <select name="make">
>    <option>Toyota</option>
> </select>
> <select name="model">
>    <option>Corolla</option>
>    <option>Yaris</option>
> </select>
>
>
>
> ________________________________________________________________________
> The Numerical Algorithms Group Ltd is a company registered in England
> and Wales with company number 1249803. The registered office is:
> Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
>
> This e-mail has been scanned for all viruses by Star. The service is
> powered by MessageLabs.
> ________________________________________________________________________
>
>



-- 
Claus Jessing, jessing.dk
---------------------------------------------
M: +45 6061 0101, P: +45 4461 0101
E: claus@xxxxxxxxxx, IM: claus@xxxxxxxxxx

Current Thread