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

Re: Re: "if-condition-return something" idiom : is it

Subject: Re: Re: "if-condition-return something" idiom : is it possible in XSLT 1 ?
From: "John Lumley john@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Jun 2014 13:11:26 -0000
Re:  Re: "if-condition-return something" idiom : is it
On 16/06/2014 13:19, Kerry, Richard richard.kerry@xxxxxxxx wrote:
And just to be clear, I am asking about XSLT1.
(I am doing DocBook transformations and am trying to parse dates as strings)

......

<xsl:template name="test.1">
   <xsl:param name="string" select="''"/>

    <xsl:if test="$check.1 = 0">
      <xsl:value-of select="$value.1" />
    </xsl:if>

    <xsl:if test="$check.2 = 0">
      <xsl:value-of select="$value.2" />
    </xsl:if>

    <xsl:if test="$check.3 = 0">
      <xsl:value-of select="$value.3" />
    </xsl:if>

   <xsl:value-of select="$value.4" />
</xsl:template>
The <xsl:choose><xsl:when><xsl:otherwise> construct is probably most appropriate for cases where the scope of the conditionality is very localised (and would involve not just patterns on the context item, as in this case where you have variables). It also has the benefit of a strict and explicit test-precedence order.

In cases where the conditionality is much more based on conditions pertaining to the context item (i.e. predicates on the node/subtree) and certainly where such possibilities are shared between different situations, then pattern-matching <xsl:template> declarations invoked through <xsl:apply-templates> may be more suitable and extensible.

Be warned however that this issue of whether conditionality is explicitly controlled within result trees or attached as predicates to templates can raise semi-religious fervour amongst some parts of the community!


-- *John Lumley* MA PhD CEng FIEE john@xxxxxxxxxxxx <mailto:john@xxxxxxxxxxxx> on behalf of Saxonica Ltd

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.