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

RE: preceding sibling headaches

Subject: RE: preceding sibling headaches
From: "Passin, Tom" <tpassin@xxxxxxxxxxxx>
Date: Tue, 22 Apr 2003 16:08:57 -0400
what test for headach
Your test

<xsl:when test = "preceding-sibling::transition[1]">

gets the first "transition" element that is a preceding-sibling, and
there always is one after the first transition element.  That is why you
got your results.  

What you really want to do is to look at the first preceding sib and see
if it is a "transition" element.  You can do this by checking its name
as follows -

<xsl:template match='paragraph'>
<p>
   <xsl:if test='preceding-sibling::*[1][name()="transition"]'>
      <xsl:attribute name='rend'>transition</xsl:attribute>
   </xsl:if>
   <xsl:value-of select='.'/>
</p>
</xsl:template>

Cheers,

Tom P

[ Paul Tremblay]
> 
> I can't understand how to use preceding sibling, despite the 
> two books I
> have on xslt.
> 
> Here is my original XML file:
> 
> <paragraph>A paragraph</paragraph>
> 
> <transition/>
> 
> <paragraph>A pargraph after a transition</paragraph>
> 
> I want to transform this to:
> 
> <p>A paragraph</p>
> 
> <p rend = "transition">A paragrah after transition</p>
> 
> Here is en excerpt form my unsuccessful code:
> 
> 
>     <xsl:template match = "paragraph">
>         <xsl:choose>
>             <xsl:when test = "preceding-sibling::transition[1]">
>                 <p rend="transition">
>                     <xsl:apply-templates/>
>                 </p>
>             </xsl:when>
>             <xsl:otherwise>
>                 <p>
>                     <xsl:apply-templates/>
>                 </p>
>             </xsl:otherwise>
>         </xsl:choose>
>     </xsl:template>
> 
> This transformation turns *all* paragraphs after a 
> </transtion> into <p
> rend ="transtion">. 
> 

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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-2013 All Rights Reserved.