Subject: Re: [xsl] Sorting and grouping unknown elements From: David Carlisle <davidc@xxxxxxxxx> Date: Fri, 21 Sep 2007 13:25:43 +0100 |
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. ________________________________________________________________________
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Sorting and grouping unkn, David Carlisle | Thread | Re: [xsl] Sorting and grouping unkn, Claus Jessing |
[xsl] Inserting an XSL variable as , Bhaskar _ | Date | Re: [xsl] Inserting an XSL variable, David Carlisle |
Month |