Re: [xsl] Enforcing element order

Subject: Re: [xsl] Enforcing element order
From: ms <mina_hurray@xxxxxxxxx>
Date: Wed, 2 May 2007 15:08:49 -0700 (PDT)
Thanks for your reply. There are a number of reasons
for the <xsl:choose> <xsl:when> statements and I will
try to explain it a little bit. 

The images appearing after <l1> need to be displayd
with a seperate footer and so they have a whole new
page sequence on the stylesheet. It is way too
complicated to explain every bit here and that is the
reason I am trying to just concentrate on the issue. 

Since there is  seperate page layout for images and
since they need to be on a seperate page with a
different footer, the following code was written for
the mfunc template:

<xsl:template match="mfunc">

 <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-templates/>
</xsl:otherwise>
 </xsl:choose>
</xsl:template>


Every image falling after <l1> can have an associated
table or text describing the image below them. That is
the reason for not(self::table[ preceding::image]) and
not(self::text[ preceding::image]).

However, implementing this code causes any <image>
under <mfunc> and before <l1> also to appear after
<l1> which is not the desired behavior.

Only images after <l1> need to appear on seperate
footer pages. 

IS there any way to test for closing tags of </l1> or
is there nay other different approach to this issue. 

It is not possible to reproduce the whole style sheet
since its way too big, and that is the reason for
asking about just the problem with a pseudo xml input.


Any suggestions are appreciated. 

--- Abel Braaksma <abel.online@xxxxxxxxx> wrote:

> 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
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread