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

Alternative for breaking out of for-each loop in XSLT

Subject: Alternative for breaking out of for-each loop in XSLT
From: <Ambika.Das@xxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Sep 2006 15:52:37 +0530
xsl stop loop
Hi,

I want to read the error description corresponding to error codes which
will be included in the output of the transformation. The structure of
the XML file (REC_STATUS.xml) containing error codes is as follows.

<?xml version="1.0" encoding="UTF-8" ?>

<error>

<header name="ERR_STATUS">
<parameter name="value" value="Permission Denied "/>
<parameter name="code" value="1"/>
<parameter name="shortStr" value="BN"/>
</header>

</error>

There is one XSL file which reads the error code as follows.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:template name="StatusDesc">
    <xsl:param name="statCode"/>
    <xsl:value-of select="$statCode"/>
    <xsl:for-each select="document('REC_STATUS.xml')//error/header">
        <xsl:variable name="varFlag">
            <xsl:for-each select="parameter">
                <xsl:if test="@name='code' and @value=$statCode">
                    <xsl:text>true</xsl:text>
                </xsl:if>
            </xsl:for-each>
        </xsl:variable>
        <xsl:if test="$varFlag='true'">
            <xsl:for-each select="parameter">
                <xsl:if test="@name='value'">
                    <xsl:value-of select="@value"/>
                </xsl:if>
            </xsl:for-each>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

The problem is that, each time I need to get an error description from
the XML file, the whole XML file needs to be parsed. For example, if the
XML file contains 100 error codes, it requires 100 iterations. Even if
the error code is found, I can't stop the iteration because XSLT doesn't
support breaking out of for each loop. This can lead to performance
issues in production.

Let me know if the above information is sufficient.

How can I break out of the for-each loop once the error code is found?

Thanks & Regards,
Ambika Prasad Das

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.