[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Re: "if-condition-return something" idiom : is it possible in XSLT 1 ?

Subject: Re: [xsl] 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

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 test="$check.2 = 0">
      <xsl:value-of select="$value.2" />

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

   <xsl:value-of select="$value.4" />
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