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

RE: following nodes until "stop-node" reached (content

Subject: RE: following nodes until "stop-node" reached (content between two nodes)
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 8 Apr 2008 14:05:58 +0100
RE:  following nodes until "stop-node" reached (content
Assuming you know there is only one "start" node and one "stop" node:

In XSLT 2.0

<xsl:variable name="start" select="*[@value='start']"/>
<xsl:variable name="stop" select="*[@value='stop']"/>
<xsl:for-each select="$start/following-sibling::*[. << $stop] | $stop">
  ...
</xsl:for-each>

In 1.0

<xsl:variable name="start" select="*[@value='start']"/>
<xsl:for-each select="$start/following-sibling::*[@value='stop' or
following-sibling::*/@value='stop']>
  ...
</xsl:for-each>

There are lots of other solutions. The most elegant use recursion, but
beginners tend to find that difficult.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: jakob Beetz [mailto:mailinglists.jakob@xxxxxxxxx] 
> Sent: 08 April 2008 13:41
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  following nodes until "stop-node" reached 
> (content between two nodes)
> 
> Dear XSLers,
> 
> given s.th. like
> 
> [...]
> <somenode value="start">Heading</somenode>
> 
> <a/>
> <b>text goes here </b>
> <b>unpredictable</b>
> <a>dasdf</a>
> 
> <somenode value="stop">something else</somenode> [...]
> 
> 
> how would I select anything (but not including) that is 
> between "somenode" with the attribute "start" and "stop"?
> 
> This is my beginers approach:
> <xsl:template match="//somenode[@value='start']">
>     <xsl:element name="entity">
>         <xsl:value-of select="."/>
>     </xsl:element>
>     <xsl:for-each select="following-sibling::*">
>         <td><xsl:value-of select="."/></td>
>      </xsl:for-each>
> </xsl:template>
> 
> how do check wether the current node in the for-eachnode is 
> the "somenode"-node with  "stop" as attribute value? Can I 
> "break out" of for each or somehow if-then the inclusion of 
> anything that comes _after_ that?
> 
> As you probably see I do not have a really good undstanding 
> of XSL/XPATH. Browsing the docs and XSL FAQ did not make me 
> wiser either.
> 
> Any help is greatly appreciated
> Thanks in advance and
> Cheers
> Jakob

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.