Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 1st, 2010, 07:16 PM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default Exit from recursive apply-templates

hi,

Iam having trouble with a recursive xsl:apply-templates.I want to come out of the recusrive xsl:apply-templates(but not termiante the XSL prematurely since i need the o/p till that loop) when a certain variable value is other than what i expect resulted from a certain external call to service but not from incoming doc in transformation.Here is my XML

XML:
<frame>
<minute>
<abc>45</abc>
<bcd>67</bcd>
</minute>
<minute>
<abc>45</abc>
<bcd>67</bcd>
</minute>
....
</frame>

XSL iam using:

<xsl:tempalte match="/">
<xsl:variable name="temp">
<xsl:apply-tempaltes select="frame/minute"/>
</xsl:variable>
<Result>
<xsl:value-of select="$temp"/>
</Result>
</xsl:template>
<xsl:tempalte match=minute>
<xsl:variable name=resp>
<xsl:value-of select="{external call}"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$resp !='0'">
<xsl:message terminate="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy -of select="$resp"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

The problem with my xsl is iam not able to capture the result till the loop has run before it failed since it terminating the xsl prematurely.Can you help me how to capture the result and also exit from template gracefully without processing remaining templates after it failed

thanks
 
Old May 1st, 2010, 07:21 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

That's not a recursive template though, is it - a recursive template would be one where the minute template would call itself again.

What happens when you just remove the <xsl:message> line - surely the template simply finished and the XSLT carries on?
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 1st, 2010, 07:33 PM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thanks sam for quick reply ,agreed not a recusrive template but some kind of looping.If i remove xsl:message it will continue to execute the other minute elements which iam a not supposed to execute even if one time the service fails since all are external service calls and it save processing time
 
Old May 1st, 2010, 07:39 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well perhaps you should turn it into a recursive template then, something like this:

Code:
<xsl:tempalte match="/"> 
<xsl:variable name="temp">
<xsl:apply-templates select="frame/minute[1]"/>
</xsl:variable>
<Result>
<xsl:value-of select="$temp"/>
</Result>
</xsl:template>

<xsl:tempalte match="minute">
<xsl:variable name="resp">
<xsl:value-of select="{external call}"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="$resp !='0'">
<!-- Do nothing -->
</xsl:when>
<xsl:otherwise>
<xsl:copy -of select="$resp"/>
<xsl:apply-templates select="following-sibling::minute[1]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old May 1st, 2010, 07:46 PM
Authorized User
 
Join Date: Jul 2009
Posts: 25
Thanks: 1
Thanked 0 Times in 0 Posts
Default

This looks cool if i add additional if condition before tht following sibing template that might work for me I will try and let u know thanks very much sam





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:apply-templates usage bsridharg XSLT 6 April 16th, 2010 03:20 PM
Can you apply templates backwards? JohnBampton XSLT 2 March 5th, 2009 01:26 PM
Exclude Elements in Apply Templates mail4kaja XSLT 18 November 29th, 2008 12:09 PM
apply-templates problem within for-each loop mister_mister XSLT 2 January 22nd, 2007 05:40 PM
Templates Won't Apply neilac333 XSLT 5 October 26th, 2006 01:39 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.