[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Enforcing element order

Subject: Re: Enforcing element order
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 02 May 2007 22:51:49 +0200
Re:  Enforcing element order
ms wrote:
Hi:

I have an xml input file as shown below:

Your XML is not well-formed. It usually helps to write XML with some XML editor and test it with your XSLT before sending it, and showing what output you currently get, and what you'd rather have instead.




As you can see elements image, table and text can
appear before and
after <l1>. Now in the PDF, I want all image, text and
table elements
to appear before l1 and the ones after to appear after
l1.

So basically, you want the element order to stay the same as the input order. The short answer is: you don't need to do anything.


Here is my XSLFO piece for tjis part:

You showed XSLT , not XSL-FO.


<xsl:choose>
<xsl:when test="*[self: :image[following -sibling:
:table] or
self::image[ following- sibling:: text] or
self::image] ">
<xsl:apply-template s select="*[not( self::image) and
not(self::table[ preceding: :image]) and
not(self::text[ preceding: :image])] "/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-template s/>
</xsl:otherwise>
</xsl:choose>


That is not valid XSLT. Please test your XSLT before sending it. Your code shows that it'd help you to find a good tutorial on the basics of XSLT processing. Using xsl:when in this way is unnecessary and superfluous.


There are several ways to solve your problem, but basically, there is no problem at all: XSLT will do what you want automatically, though here's one:

<xsl:template match="/">
  <xsl:apply-templates select="mfunc/*" />
</xsl:template>

<xsl:template match="l1">
   ... do something with l1...
   <xsl:apply-templates />
</xsl:template>

<xsl:template match="image">
   ... do something with image ...
   <xsl:apply-templates />
</xsl:template>

<xsl:template match="text">
   ... do something with text ...
   <xsl:apply-templates />
</xsl:template>


Note that the order of the xsl:template are unimportant. The output will look like you want: the elements before <l1> are processed before <l1> and the elements after <l1> are processed thereafter. And so will your output.




Can anyone suggest a different apprach to this
problem?

Yep, see above ;)


Cheers,
-- Abel Braaksma

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2007 All Rights Reserved.