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

RE: <xsl:sort>

Subject: RE: <xsl:sort>
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Sat, 07 May 2005 08:33:34 +0000
RE:  <xsl:sort>
aspsa, it looks like your document initially has some descriptive elements (header, paragraph(s), subheader, etc), then a list of product elements. I assume you want your output to be of similar structure: first descriptive text, then a list of products. Only, the products should be sorted.

So do something like this:

<xsl:template match="document">
   <xsl:value-of: ...header
   <xsl:value-of: ...subheader

<!-- now the list

   <xsl:apply-templates select="product">
       <xsl:sort select="."/>
   /end-product
/end-document

Then an product template would get products in the right order:

<xsl:template match="product"
 ...
/end-product


As a matter of style it may be better specifically to select/process nodes you want, than iterate all child nodes with child::, then branch based on a subsequent test. In XSL the presence of a specifically-matching template is an implicit suggestion that you're interested in corresponding applicable nodes, and you'd be best of taking advantage of this built-in mechanism for selecting-and-branching rather than recreating it with <xsl:if>


Regards,

--A


From: aspsa <aspsa@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  <xsl:sort>
Date: Sat, 07 May 2005 03:37:44 -0400

Hi, folks.

I have an XML document which structure is the following:

<document>
  <header>
  <paragraph>
  <subheader>
  <paragraph>
  .
  .
  .
  <product>
    <partname>
    <category>
    .
    .
    .
  </product>
  <product>
    <partname>
    <category>
    .
    .
    .
  </product>
  .
  .
  .
</document>

In a template that matches on "document", I have the following:

<xsl:template match="document">
  <xsl:for-each select="child::node()">
    // etc...
  </xsl:for-each>
</xsl:template>

The XSLT stylesheet works fine, but now I need to sort the "product"
elements based upon the "category" element and in descending order. The
category content is numeric.

How would I execute this from within the "document" template?

Here's what I've tried.

<xsl:template match="document">
<xsl:for-each select="child::node()">
<xsl:if test="product">
<xsl:apply-templates select=".">
<xsl:sort select="category" data-type="number" order="descending" />
</xsl:apply-templates>
</xsl:if>
</xsl:for-each>
</xsl:template>


Where am I going wrong? Thanks for your feedback.


Respectfully,


ASP


_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


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.