[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Sorting and grouping unknown elements

Subject: Re: Sorting and grouping unknown elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 25 Sep 2007 13:17:22 +0100
Re:  Sorting and grouping unknown elements
>  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. 
________________________________________________________________________

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.