[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: "jakob Beetz" <mailinglists.jakob@xxxxxxxxx>
Date: Wed, 9 Apr 2008 15:57:18 +0200
Re:  following nodes until "stop-node" reached (content
Gentlemen,

thank you all for your valuable and quick suggestions, they were
really helpful for understanding the whole thing.

On Tue, Apr 8, 2008 at 3:05 PM, Michael Kay <mike@xxxxxxxxxxxx> wrote:
>
>  Assuming you know there is only one "start" node and one "stop" node:
>

unfortunatly that is not the case (trying to scrape information from
hundreds of html pages), I missed to mention this in my original
problem statement. This meant for me that I could not tackle the
problem with any of the XPath and grouping solutions that were
suggested.

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

That was the key to the solution.
Below is my quick'n'dirty recursive approach to it (works fine for my
real-world problem)

A big "Thank you" to all of you again,
Cheers
Jakob

<xsl:template match="/">
	<xsl:apply-templates select="//somenode[@value='start']"/>
</xsl:template>

<xsl:template match="//somenode[@value='start']">

	<xsl:call-template name="copy-until-stop">
		<xsl:with-param name="current_node"
select="self::node()/following-sibling::*[1]"/>
		<xsl:with-param name="count" select="0"/>
	</xsl:call-template>
</xsl:template>

<xsl:template name="copy-until-stop">
	<xsl:param name="current_node" />
        <xsl:param name="count" />

	<!--test if stop tag is reached. To avoid endless recursion break out
after at most 5000 nodes-->
	<xsl:if test="not($current_node[@value='stop']) and $count &lt; 5000" >
		<xsl:copy-of select= "$current_node"/>
		<xsl:call-template name="copy-until-stop">
			<xsl:with-param name="current_node"
select="$current_node/following-sibling::*[1]"/>
			<xsl:with-param name="count" select="$count+1"/>
		</xsl:call-template>
    </xsl:if>
	
</xsl:template>




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