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

Re: Conditional Selection of Nodes

Subject: Re: Conditional Selection of Nodes
From: "Kyle D. Morton" <kyle_morton@xxxxxxxxxxx>
Date: Wed, 9 May 2001 21:03:00 -0400
kyle d morton
This sort of does it...It breaks down if child element names are repeated
out of sequence.

<xsl:template match="/">

 <foo>
 <xsl:variable name="nodeList" select="foo/child::*" />

 <xsl:for-each select="$nodeList">
  <xsl:variable name="curPos" select="position()" />
  <xsl:variable name="curName" select="name()" />
  <xsl:variable name="nextName" select="name(following-sibling::*)" />

  <xsl:if test="$curName!=$nextName">
   <xsl:if test="$curName!='p'">
    <p>
    <xsl:for-each select="$nodeList[name()=$curName and
$curPos>=position()]">
     <xsl:copy>
      <xsl:value-of select="text()"/>
     </xsl:copy>
    </xsl:for-each>
    </p>
   </xsl:if>
   <xsl:if test="$curName='p'">
    <xsl:copy>
     <xsl:value-of select="text()"/>
    </xsl:copy>
   </xsl:if>
  </xsl:if>

 </xsl:for-each>
 </foo>

</xsl:template>


----- Original Message -----
From: Ciaran Byrne <ciaran.byrne@xxxxxxx>
To: Xsl-List <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, May 09, 2001 4:41 PM
Subject:  Conditional Selection of Nodes


> Hi all,
> The following question has been teasing me lately
> and I was hoping someone has an answer.
>
> I have the following XML ...
>
> <foo>
>    <b>content</b>
>    <b>more content</b>
>    <p>yet more content</p>
>    <i>some more conent</i>
> </foo>
>
>
> and what I want is to put all child elements of 'foo' that
> are not in 'p' elements into a 'p' element, in order.
>
> <foo>
>    <p>
>      <b>content</b>
>      <b>more content</b>
>    </p>
>    <p>yet more content</p>
>    <p>some more content</p>
> </foo>
>
> The key issue is to avoid putting 'p' elements around every sibling i.e.
>
> <foo>
>    <p>
>      <b>content</b>
>    </p>
>    <p>
>      <b>more content</b>
>    </p>
> etc.
> </foo>
>
> I've tried a few approaches yet no joy ;o( Any help is appreciated
>
> Ciaran.
>
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>

 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.