Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 26th, 2007, 07:37 PM
Registered User
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Simple sort question

Looking for some help here.

I have a simple XML file with products with the following format:

<products>

<product type="shop" id="4">
<name>Drill Bit Set</name>
<description>A set of 24 high-speed drill bits in a steel case.</description>
<feature>High-speed steel</feature>
<feature>Titanium coated for long life</feature>
</product>

<product type="garden" id="1">
<name>Lawn Mower</name>
<description>A great push mower</description>
<feature>Runs great</feature>
</product>

<product type="garden" id="3">
<name>Leaf Blower</name>
<description>A great tool to clean up the yard fast</description>
<feature>210mph</feature>
<feature>110Volts</feature>
</product>

<product type="shop" id="2">
<name>Hand Plane</name>
<description>Smooth those edges on boards fast.</description>
<feature>Cast iron construction</feature>
<feature>High-carbon blade</feature>
</product>

.
.

These products may or may not be in any particular order. What I need is an XSLT file that will generate a sorted list of products by name based on whether I specify either "garden" or "shop".

I'd be hanged if this has me stumped. Any help would be really great!

Thanks much,
Gary
 
Old October 27th, 2007, 03:16 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure exactly what you want, but it sounds something like

<xsl:template match="products">

  <xsl:for-each select="product[@type='garden']">
    <xsl:sort select="name"/>
    <xsl:copy-of select="."/>
  </xsl:for-each>

  <xsl:for-each select="product[@type='shop']">
    <xsl:sort select="name"/>
    <xsl:copy-of select="."/>
  </xsl:for-each>

</xsl:template>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 27th, 2007, 12:52 PM
Registered User
 
Join Date: Oct 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael,

That worked beautifully. I appreciate your help!

Best regards,
Gary





Similar Threads
Thread Thread Starter Forum Replies Last Post
Need Xsl to Sort the following simple xml: Takashi321 XSLT 3 August 27th, 2007 11:54 AM
xsl:sort Question kwilliams XSLT 6 July 18th, 2005 08:39 AM
sort by question elladi Classic ASP Databases 1 March 29th, 2005 11:12 AM
Sort order Question Tere Crystal Reports 1 February 14th, 2005 03:18 PM
Sort Method question rgalehouse Javascript 1 February 10th, 2004 07:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.