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

Re: Newbie question on XSL transformations: multiple

Subject: Re: Newbie question on XSL transformations: multiple sorts on element attributes
From: Rob Newman <rlnewman@xxxxxxxx>
Date: Tue, 6 Feb 2007 16:40:58 -0800
Re:  Newbie question on XSL transformations: multiple
Hi Abel,

You have got the point - your summary is correct.
Unfortunately that first sort (1) causes xsltproc to seg-fault again. I will keep trying to figure it out.


Thanks for all the help.
- Rob

On Feb 6, 2007, at 4:10 PM, Abel Braaksma wrote:

Rob Newman wrote:

Datalogger elements right now are not sorted. Whichever comes first in input.xml gets output first in output.xml. I have no control of the order in input.xml. Hence the need to sort them.

Thanks for the more verbose input. I often have the same trouble getting my point through, but your last clarifications sure make things easier. Let me summarize, to find out if I got the point now:


1. You want to order all datalogger elements based on the only child element of pfarr, which is a pfstring and has an attribute @name='dlt'. Highest number first.
2a. You do not want to order the param elements, because they are already ordered
2b. You do want to order the param elements.


I wasn't sure between 2a and 2b, so I give you both answers. Resolving (1) first:

<xsl:apply-templates select="pfarr/pfarr/pfarr" >
<xsl:sort select="pfstring[@name = 'dlt']" data-type="number" order="descending"/>
</xsl:apply-templates>


What this does is the following: for each pfarr element, it orders for the child "pfstring" that has an attribute '@name' with the value 'dlt'. You may be tempted to use the element names of the output, but you should always use the nodes from the input (no other possibility). The starting point for the expression always is each element that is selected by the enclosing xsl:apply-templates. Here, "pfarr/pfarr/pfarr" returns a selection of "pfarr" elements. These are ordered based on there pfstring children. The trick I always use to find out whether I have a legal path is, append them together:

"pfarr/pfarr/pfarr"  plus   "pfstring[@name = 'dlt']" yields:
pfarr/pfarr/pfarr/pfstring[@name = 'dlt']

if this resulting path is not correct, i.e. does not select anything, the xsl:sort will not have any effect.


Solving 2a: remove the other sorts.


Solving 2b: leave only the following in place to order param elements ascending and by name (in your example, both input and output were sorted, so I wasn't sure you needed this)

 <xsl:apply-templates select="pfstring">
     <xsl:sort select="@name" />
 </xsl:apply-templates>



Sorry about this - hopefully this cleans the canvas and it is clear to all what I am trying to do. Thanks again.

np. See above.

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.