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
Jerry JanofskySubject: Newbie Sorting Question
Author: Jerry Janofsky
Date: 08 Aug 2006 01:38 PM
Please correct me if I am wrong...

I am writing an XSLT stylesheet to transform data from an XML document. I just realized that I need to make sure my XSLT creates the same output irrelevant of the order of sibbling elements in in XML doc.

For instance, what if I have the following address node:

<address>
<state>MA</state>
<zip>01757</zip>
<street>258 Main Street, Suite 212</street>
<city>Milford</city>
</address>

If my template is like the follwing then it comes out wrong. Does this mean I need to make sure the address element has its sub elements in the correct order or do I have to fix my template?

<xsl:template match="address">
<xsl:apply-templates />
</xsl:template>

Postnext
Ivan PedruzziSubject: Newbie Sorting Question
Author: Ivan Pedruzzi
Date: 08 Aug 2006 03:00 PM
Jerry,

<xsl:apply-template/> processes child nodes in the same order they are located in the input document.

what do you mean by "it comes out wrong"?

Could you please post a full example XSLT + input XML and the expected result?

Which XSLT processor are you running?
Which Stylus Studio build?

Thank You
Ivan Pedruzzi
Stylus Studio Team

Postnext
Jerry JanofskySubject: Newbie Sorting Question
Author: Jerry Janofsky
Date: 08 Aug 2006 03:50 PM
Ivan, I just meant the order of output wouldn't be City,State,Zip. I guess I know the answer now though. Thanks.

Postnext
Michael GrimleySubject: Newbie Sorting Question
Author: Michael Grimley
Date: 08 Aug 2006 03:33 PM
You have at least three options:

1. If you use a schema to validate your XML, you can ensure that the elements will always be in the order you expect.

2. Change your template to get the info you need in the order that you need it. For example:

a. <xsl:template match="address">
<xsl:apply-templates select="street"/>
<xsl:apply-templates select="city"/>
<xsl:apply-templates select="state"/>
<xsl:apply-templates select="zip"/>
</xsl:template>

b. <xsl:template match="address">
<p><xsl:value-of select="street"/>
<br/><xsl:value-of select="city"/>
<br/><xsl:value-of select="state"/>
<br/><xsl:value-of select="zip"/>
</xsl:template>

Posttop
Jerry JanofskySubject: Newbie Sorting Question
Author: Jerry Janofsky
Date: 08 Aug 2006 03:47 PM
Ok, thanks for the info.

 
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.