Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Q: Out of order document

Reply
Thread Tools

Q: Out of order document

 
 
G. Ralph Kuntz, MD, MS
Guest
Posts: n/a
 
      02-14-2008
How do people deal with out-of-order document? Let me clarify.

Let's say we have an input document having the following format:

<document>
section 1
section 2
section 3
</document>

we want the resulting output document to have the structure

<document>
section 3
section 2
section 1
</document>

Since the xsl template matching will match section 1, then section 2,
etc. how do we get the output into the format we want?

Do you use param(s) to store intermediate values?

Thanks, Ralph
 
Reply With Quote
 
 
 
 
Johannes Koch
Guest
Posts: n/a
 
      02-14-2008
G. Ralph Kuntz, MD, MS schrieb:
> How do people deal with out-of-order document? Let me clarify.
>
> Let's say we have an input document having the following format:
>
> <document>
> section 1
> section 2
> section 3
> </document>
>
> we want the resulting output document to have the structure
>
> <document>
> section 3
> section 2
> section 1
> </document>
>
> Since the xsl template matching will match section 1, then section 2,
> etc. how do we get the output into the format we want?


xsl:sort?
--
Johannes Koch
In te domine speravi; non confundar in aeternum.
(Te Deum, 4th cent.)
 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      02-14-2008
G. Ralph Kuntz, MD, MS wrote:
> How do people deal with out-of-order document? Let me clarify.
>
> Let's say we have an input document having the following format:
>
> <document>
> section 1
> section 2
> section 3
> </document>
>
> we want the resulting output document to have the structure
>
> <document>
> section 3
> section 2
> section 1
> </document>
>
> Since the xsl template matching will match section 1, then section 2,
> etc. how do we get the output into the format we want?


Here is an example, assuming the document element has section child
elements like this

<document>
<section>section 1</section>
<section>section 2</section>
<section>section 3</section>
</document>

then you can process them and sort in descending order

<xsl:stylesheet
xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslutput method="xml" indent="yes"/>

<xsl:template match="document">
<xsl:copy>
<xsl:apply-templates select="section">
<xsl:sort select="position()" order="descending"
data-type="number"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>

to reverse the original order.



--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Joseph Kesselman
Guest
Posts: n/a
 
      02-14-2008
Do you really mean the "section" lines to be raw text, as you've shown
them? If so, you need to do that with string processing, which is
possible but somewhat awkward in XSLT.

If they have XML structure, then as others have said you can use
sorting... or, if you know the expected sections in advance, you can
simply have the template for <document> explicitly process them in a
specific order by using more specific apply-template selections.

--
Joe Kesselman / Beware the fury of a patient man. -- John Dryden
 
Reply With Quote
 
G. Ralph Kuntz, MD, MS
Guest
Posts: n/a
 
      02-14-2008
I meant xml sub-sections. I found the answer. I did not know that
<xsl:apply-templates> could take an argument.

Thanks.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If you get an order # does it mean the order is accepted? =?Utf-8?B?U3RldmUxMDc3?= Windows 64bit 3 05-12-2005 11:46 PM
[XSLT] Question about the include order when "document()" is called in a "for-each" instruction. Phil XML 3 05-27-2004 07:29 PM
Traversion order cf. output order in XSL Soren Kuula XML 2 02-01-2004 09:10 AM
In which order are files looked for when loaded/requierd - and what'sthe order of suffixes? Stephan Kämper Ruby 2 01-18-2004 02:07 PM
How to Display DropDownList with preserved order (custom order) cspoh ASP .Net Web Controls 0 07-31-2003 09:19 AM



Advertisments