|
Subject:
|
Need help with XSLT sort
|
|
Posted By:
|
nyctechwriter
|
Post Date:
|
8/18/2006 1:51:32 PM
|
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#shortDescription"/> <implements>java.beans.BeanInfo</implements> <category>Feeds</category> (need to sort on this value) <properties> <property id="com.j2fe.feeds.activities.FileSplitBase#property#businessFeed"> <displayName>Business Feed</displayName> <shortDescription id="com.j2fe.feeds.activities.FileSplitBase#property#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>
|
|
Reply By:
|
mhkay
|
Reply Date:
|
8/18/2006 1:57:46 PM
|
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
|
|
Reply By:
|
nyctechwriter
|
Reply Date:
|
8/18/2006 2:27:05 PM
|
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!!
|