xsl-list
[Top] [All Lists]

[xsl] Sorting and grouping unknown elements

2007-09-21 04:48:02
Hi gurus

I'm very new to xml/xsl transformation and am faced with the following
problem. I have an xml file with a number of rows.
Each row contains an unknown (but identical in terms of element names)
set of elements. I would like to create a drop down list
for each element below my row element.

Eg. if I had this XML:

<rowset>
  <row>
    <make>Toyota</make>
    <model>Yaris</model>
    <color>Red</color>
  </row>
  <row>
    <make>Toyota</make>
    <model>Corolla</model>
    <color>Blue</color>
  </row>
</rowset>


I would like to get this html:

<select name="make">
   <option>Toyota</option>
</select>
<select name="model">
   <option>Corolla</option>
   <option>Yaris</option>
</select>
<select name="color">
   <option>Blue</option>
   <option>Red</option>
</select>



And this XML:

<rowset>
  <row>
    <name>Joe</name>
    <address>123 Wide Av.</address>
  </row>
  <row>
    <name>Joe</name>
    <address>321 Narrow St.</address>
  </row>
</rowset>


Should produce this html:

<select name="name">
   <option>Joe</option>
</select>
<select name="address">
   <option>123 Wide Av.</option>
   <option>321 Narrow St.</option>
</select>




I have tried with something like this and all sorts of different
tweeks but I cant get to work :(

<xsl:for-each select="row/*">
   <xsl:sort/>
   <xsl:param name="_param" select="name()"/>
   Debug: <xsl:value-of select="$_param"/>
                                                        
        <xsl:for-each select="//{name()}[not(. = following::{name()})]">
                <xsl:sort/>
                <option><xsl:value-of select="."/></option>
        </xsl:for-each>
                                                                
</xsl:for-each>


Can anyone help me out here?

Thanks in advance...

-- 
Claus Jessing, jessing.dk
---------------------------------------------
M: +45 6061 0101, P: +45 4461 0101
E: claus(_at_)jessing(_dot_)dk, IM: claus(_at_)jessing(_dot_)dk

--~------------------------------------------------------------------
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>
--~--