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

Re: Writing an optional element

Subject: Re: Writing an optional element
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 05 Jul 2004 17:12:35 -0400
xsl optional element
At 03:41 PM 7/5/2004, it was written:
Nestor> Is there a better way to do it than:

    Nestor> <xsl:choose> <xsl:when test="condition"> <element>
    Nestor> ... processing instructions ...  </element> </xsl:when>
    Nestor> <xsl:otherwise> ... repeat processing instructions ...
    Nestor> </xsl:otherwise> </xsl:choose>

If by a better way, you mean you want to avoid writing the same
"continue processing" code, then you could call a named template
each time. Said named template to contain the common code.

Also, there are times when conditional logic can be handled by template matches:


<xsl:template match="span[@display='i']">
  <i>
    <xsl:apply-templates/>
  </i>
</xsl:template>

<xsl:template match="span">
  <xsl:apply-templates/>
</xsl:template>

Because the first template has a higher priority than the second, it will fire in preference to the second when the condition in the predicate is true; the second template catches those cases for which the condition isn't true.

Not every condition can be handled like this, due to restrictions on what may appear in patterns (e.g. no variable references are allowed). Nevertheless this is very useful, and certainly clean compared to those somewhat bloated choose/when/otherwise combinations.

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.