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

Re: Breaking from the loop (for-each or apply-template

Subject: Re: Breaking from the loop (for-each or apply-template)
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Fri, 12 Aug 2005 15:42:48 -0400
xslt loop for
Hi,

The specification of xsl:message is soft, the instruction optional, and not all processors support it. I suppose this softness is simply out of a recognition that not all architectures are equally able to provide the functionality.

A more conventionally XSLT-ish way to approach the problem would be to define the error condition up front and simply design the stylesheet to return warnings instead of (or in addition to) the usual thing, if any error conditions obtain. So for example if I defined my condition as "all <value> elements must have content that casts to a number" (so, for example, "0" is okay but not just whitespace) and my input had (somewhere inside)

<value>5</value>
<value>9</value>
<value></value>
<value>Hooey!</value>

my XSLT could have

<xsl:variable name="errors" select="//value(not(number(.))"/>

<xsl:template match="/">
  <xsl:choose>
    <xsl:when test="$errors">
      <!-- erroneous 'value' elements are found -->
      <xsl:apply-templates select="$errors" mode="report-errors"/>
    </xsl:when>
    <xsl:otherwise>
      <!-- no errors: process normally -->
      <xsl:apply-templates/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

As noted above, you could leave out the xsl:choose and have the errors reported in addition to, rather than instead of, normal output.

Note that this approach only works on "errors" that can be defined ahead and that appear within otherwise proper well-formed XML.

Also, no "loop" is being "broken" -- no specification of flow of control is really needed here, just a plain old declaration that "if X is true, I want X', otherwise I want Y".

Cheers,
Wendell

At 03:20 PM 8/12/2005, you wrote:
Oleg,

    I've never used Cocoon, but I can tell you that Xalan 2.5.1 and
above (2.7 was released a few days ago) do support the xsl:message
instruction.

Regards,
Kenneth


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

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.