XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Ave DalSubject: Sorting on an element that is indirectly referenced
Author: Ave Dal
Date: 23 Jan 2007 06:55 PM
Originally Posted: 23 Jan 2007 06:54 PM
Hello,

I'm trying to sort some output with XSL on an attribute of a "referenced" (for lack of a better term) element. Here's my XML.

=== BEGIN MEETING.XML ===

<report>
<locations>
<location id="1">
<name>Location 1</name>
</location>
<location id="2">
<name>Location 2</name>
</location>
</locations>
<meeting>
<date>20070101</date>
<name>Beta</name>
<description>Meeting at Location 2</description>
<location-id>1</location-id>
</meeting>
<meeting>
<date>20070303</date>
<name>Alpha</name>
<description>Meeting at Location 1</description>
<location-id>2</location-id>
</meeting>
<meeting>
<date>20050606</date>
<name>Beta</name>
<description>Another Meeting at Location 1</description>
<location-id>1</location-id>
</meeting>
<meeting>
<date>20070611</date>
<name>Hotel</name>
<description>Another Meeting at Location 2</description>
<location-id>2</location-id>
</meeting>
</report>
=== END MEETING.XML ===


As you can see, each <meeting> contains a <location-id> which references a <location> element defined elsewhere in the XML data. This is done to reduce redundancy and keep the document smaller.

In my stylesheet, I need to sort meetings by their location name. Here's my XSL:


=== BEGIN MEETING-REPORT.XSL ===
<xsl:template match="/">
<html>
<body>
<xsl:for-each select=".//meeting">
<xsl:variable name="location_id" select="location-id"/> <xsl:sort select="/report/locations/location[@id=$location_id]/name"/>
<xsl:sort select="name"/>
<xsl:sort select="date"/>
<xsl:call-template name="meeting"/>
</xsl:for-each>
</body>
</html>
</xsl:template>

=== END MEETING-REPORT.XSL ===

Now this doesn't work. According to my parser, it appears that <xsl:sort> elements must come immediately <xsl:for-each> so I'm not able to declare the $location_id variable. Is there another way to accomplish what I'm trying to do?

Posttop
Tony LavinioSubject: Sorting on an element that is indirectly referenced
Author: Tony Lavinio
Date: 25 Jan 2007 06:03 PM
General XSLT questions and questions not pertaining to Stylus Studio
should be asked on the XSL-LIST run by Mulberry Technologies.

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.