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 August 18th, 2006, 01:51 PM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need help with XSLT sort

Hi all, well I am fairly new to XSLT but I managed to write a stylesheet that takes in some proprietary XML code and converts it to cleaner, DITA-compliant code. Below I have pasted in a sample of the source, as well as my XSLT. Everything is working great, except my XSLT simply outputs code in the same order as it appears in the source code. I need to sort the ouput based on the <category> tag. For example, all "beans" in the Feeds category should be grouped together, all beans in the misc category should be grouped together, all beans without a value for category should be grouped together, etc. Any tips would be greatly appreciated!

Source Code:

<bean id="com.j2fe.feeds.activities.FileSplitBase">
        <displayName>FileSplitBase</displayName>
        <shortDescription id="com.j2fe.feeds.activities.FileSplitBase#shortD escription"/>
        <implements>java.beans.BeanInfo</implements>
        <category>Feeds</category> (need to sort on this value)
        <properties>
            <property id="com.j2fe.feeds.activities.FileSplitBase#proper ty#businessFeed">
                <displayName>Business Feed</displayName>
                <shortDescription id="com.j2fe.feeds.activities.FileSplitBase#proper ty#businessFeed#shortDescription"/>
                <output>no</output>
                <input>yes</input>
                <required>yes</required>
                <type>java.lang.String</type>
            </property>
</bean>

My XSLT:

<xsl:template match="documentation">

<topic>

<xsl:attribute name="id">JavaBeans</xsl:attribute>

<title>JavaBeans Documentation</title>

<xsl:apply-templates select="bean"/>

</topic>

</xsl:template>

<xsl:template match="bean">

<bean>

<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>

<title><xsl:value-of select="displayName"/></title>

<shortdesc><xsl:value-of select="shortDescription"/></shortdesc>

<beanbody>

<properties>

<xsl:attribute name="id"><xsl:value-of select="@id"/>Props</xsl:attribute>

<prophead>

<propdisplaynamehd>Display Name</propdisplaynamehd>
<propdeschd>Description</propdeschd>
<proptypehd>Type</proptypehd>
<propinputhd>Input</propinputhd>
<propdependsonhd>Dependencies</propdependsonhd>

</prophead>

<property>

<propdisplayname><xsl:value-of select="displayName"/></propdisplayname>
<propdesc><xsl:value-of select="shortDescription"/></propdesc>
<proptype><xsl:value-of select="type"/></proptype>
<propinput><xsl:value-of select="input"/></propinput>
<propdependson><xsl:value-of select="dependsOn"/></propdependson>

</property>

</properties>

</beanbody>

</bean>

</xsl:template>
 
Old August 18th, 2006, 01:57 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Just change

<xsl:apply-templates select="bean"/>

to

<xsl:apply-templates select="bean">
  <xsl:sort select="category"/>
</xsl:apply-templates>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 18th, 2006, 02:27 PM
Registered User
 
Join Date: Aug 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Holy smokes - a reply from Yoda himself !! I have your XSLT book right in front of me Mr. Kay. Thanks so much for your help - worked like a charm!!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamic sort order or sort datatype kapy_kal XSLT 2 September 18th, 2007 02:10 PM
how to sort cross tab.sort based on row total joxa83 Crystal Reports 7 March 2nd, 2006 09:12 AM
XSLT Dynamic xsl:sort Method kwilliams XSLT 2 July 20th, 2005 03:19 PM
XSLT-- xsl:sort help... debo XSLT 2 December 3rd, 2004 04:25 PM
Sort using XSLT xrow XSLT 5 October 14th, 2004 10:59 AM





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