xsl-list
[Top] [All Lists]

Re: [xsl] Sorting and grouping unknown elements

2007-09-25 05:17:42


 Model and color is not processed (at least not the way I expect it)

unfortunately that doesn't tell the rest of us what output you need.

   
 <xsl:for-each select="row/*[generate-id(.)=generate-id(key('n',name()))]">


selects the children of row if they are the first elements in the
document with that name. that doesn't select much in your revised
document as in most cases the first instance of each eleemnt is not
under row.

Two possible fixes, first chage that to

    <xsl:for-each select="*/*[generate-id(.)=generate-id(key('n',name()))]">

so you test all grandchilfren not just children of row,
and same change (row to *) in
        <xsl:for-each 
select="../../*/*[generate-id(.)=generate-id(key('v',concat(name(current()),.)))]">


 that gives


$ saxon rs2.xml rs1.xsl
<?xml version="1.0" encoding="utf-8"?>
<select name="color">
   <option>Blue</option>
   <option>Red</option>
   <option>White</option>
</select>
<select name="make">
   <option>Toyota</option>
</select>
<select name="model">
   <option>Corolla</option>
   <option>Supermarket</option>
   <option>Yaris</option>
</select>
<select name="name">
   <option>Tesco</option>
</select>



or perhaps you do just want children of row in which case put them back to back
to

    <xsl:for-each select="row/*[generate-id(.)=generate-id(key('n',name()))]">
        <xsl:for-each 
select="../../row/*[generate-id(.)=generate-id(key('v',concat(name(current()),.)))]">

but make sure that only children of row are indexed, so that the test
becomes, list the children of row that are the first such children with
that name, so change

  <xsl:key  name="n" match="*" use="name()"/>
  <xsl:key  name="v" match="*" use="concat(name(),.)"/>

to

  <xsl:key  name="n" match="row/*" use="name()"/>
  <xsl:key  name="v" match="row/*" use="concat(name(),.)"/>

which makes

$ saxon rs2.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>


Note no information from the cvr row)

David

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