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

Re: Infinite Loop when param empty

Subject: Re: Infinite Loop when param empty
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 22 Jul 2004 16:56:31 -0400
xsl when param
Hi Karl,

At 01:00 PM 7/22/2004, you wrote:
I have a param which is populated with an XML source.

The paramter is declared like this:
<xsl:param name="ENTRY_TEMPLATE" select="/"/>

My top level match is:
<xsl:template match="/">

Within this template rule I apply the following:
<xsl:apply-templates select="$ENTRY_TEMPLATE"/>

If the param ENTRY_TEMPLATE is not set, I end up with an infinite loop.  Is
this normal behaviour?  I'm guessing that maybe it is bad practice to
declare the param as I have.

It is normal behavior, since when your parameter is set to the root, selecting it and applying templates applies the template matching the root ... etc. ad infinitum.


But it's easy enough to set the parameter's default to something else. A node set containing no nodes will do nicely ... you could select="/parent::*" (or select="/.." if you prefer), which selects the parent of the root -- which doesn't exist. Accordingly in such cases templates will be applied to nothing, thereby avoiding the problem of the template selecting its own current node to apply itself to (thus selecting its own current node).

A more robust solution could actually trap the troublesome case by testing whether the parameter identifies the root:

<xsl:when test="generate-id(/) = generate-id($ENTRY_TEMPLATE)">
  <xsl:message>Sorry, can't process the root as entry template</xsl:message>
</xsl:when>
<xsl:otherwise>
  <xsl:apply-templates select="$ENTRY_TEMPLATE"/>
</xsl:otherwise>

Cheers,
Wendell


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