xsl-list
[Top] [All Lists]

Re: [xsl] Sorting and grouping unknown elements

2007-09-21 05:26:05


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. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--