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

trying for: a template that calls apply-templates on i

Subject: trying for: a template that calls apply-templates on its children only until some condition is reached
From: Nick Mealy <nick@xxxxxxxxxx>
Date: Wed, 15 Jun 2005 14:16:31 -0700
nick mealy
Hi all,

im trying to do something a little unusual, but which is surprisingly quite hard.

for a given template, i only want it to keep rendering it's children until it's counted a certain number of occurrences of a particlar element (in this case br elements), and then stop applying templates altogether.
As to why I need this, basically there are some rare cases where our system returns xml that's just enormous, so enormous that rendering takes way too long. And since the data coming back is to large to be useful anyway, i want to just render the first few lines and then stop completely.


Maybe this isnt a job for XSLT, but i'm not quite ready to admit that..

I first tried a massively inefficient way:

<xsl:template match="myTroublesomeNode">
  <xsl:for-each select="node()">
      <xsl:if test="count(preceding-sibling::br)&lt;20">
          <xsl:apply-templates select="."/>
      </xsl:if>
  </xsl:for-each>
</xsl:template>

but calling this count(preceding-sibling::br) on every node is a clear case of the cure being worse than the disease.


So... since then I've been trying recursion, but I clearly dont know what im doing cause the parser complains about infinite recursion in the following snippet...


(I have a sense that the way im using my $nextNode param and the preceding/following axes is wrong, but i cant improve on it. )

<xsl:template match="myTroublesomeNode">
  <xsl:call-template name="brCounter">
      <xsl:with-param name="nextNode" select="node()[1]"/>
  </xsl:call-template>
</xsl:template>

<!-- danger, i contain infinite recursion somewhere, so take care -->
<xsl:template name="brCounter">
<xsl:param name="nextNode" />
<xsl:if test="count($nextNode/preceding-sibling::br)&lt;10">
<xsl:apply-templates select="$nextNode"/>
<xsl:call-template name="brCounter">
<xsl:with-param name="nextNode" select="$nextNode/following-sibling::node()[1]" />
</xsl:call-template>
</xsl:if>
<xsl:if test="count($nextNode/preceding-sibling::br)&gt;=10">
I've had all i can stands. i cant stands no more.
</xsl:if> </xsl:template>


Any help or advice would be greatly appreciated... n

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.