W3C home > Mailing lists > Public > public-qt-comments@w3.org > November 2009

[Bug 8253] New: Allow xsl:variable before xsl:param

From: <bugzilla@wiggum.w3.org>
Date: Tue, 10 Nov 2009 01:52:13 +0000
To: public-qt-comments@w3.org
Message-ID: <bug-8253-523@http.www.w3.org/Bugs/Public/>
http://www.w3.org/Bugs/Public/show_bug.cgi?id=8253

           Summary: Allow xsl:variable before xsl:param
           Product: XPath / XQuery / XSLT
           Version: Recommendation
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: XSLT 2.0
        AssignedTo: mike@saxonica.com
        ReportedBy: gbeauch1@jhu.edu
         QAContact: public-qt-comments@w3.org


Hello. I've been using XSLT for a while and I recently ran into a small
issue. Specifically, the recommendation forbids intermixing of
xsl:variable and xsl:param, which would be useful for default parameter 
values. This seems to me to be unnecessarily restrictive.

The XSLT 2.0 recommendation defines xsl:template as follows:

<xsl:template
    match? = pattern
    name? = qname
    priority? = number
    mode? = tokens
    as? = sequence-type>
    <!-- Content: (xsl:param*, sequence-constructor) -->
</xsl:template>

<xsl:param> elements can be assigned default values using the "select"
attribute or child content, and the default value can be defined in 
terms of the value of other parameters. This is useful, as it allows for 
dynamic defaults. However, there have been times where I would like to 
reuse a complex XPath expression in the default values of several 
parameters. For example, I would like to be able to rewrite this:

<xsl:template name="blah">
      <xsl:param name="param0"/>
      <xsl:param name="param1" select="$param0/a/long[@expr][1]" />
      <xsl:param name="param2" select="$param0/a/long[@expr][2]" />
</xsl:template>

as this:

<xsl:template name="blah">
      <xsl:param name="param0" />
      <xsl:variable name="tempVar" select="$param0/a/long[@expr]" />
      <xsl:param name="param1" select="$tempVar[1]" />
      <xsl:param name="param2" select="$tempVar[2]" />
</xsl:template>

Because the content of xsl:template is:

(xsl:param*, sequence-constructor)

...I am not allowed to put an xsl:variable before an xsl:param. Is there
any reason why this should be the case?

As a simple workaround, I can just change the <xsl:variable> to
<xsl:param> and it works exactly as expected, except that now $tempVar
is exposed as a template parameter when it was really supposed to be for
internal template use only.

Is there any chance that this could be relaxed in the next version of
XSLT and the xsl:template content changed to:

((xsl:variable | xsl:param)*, sequence-constructor)

...? Likewise for xsl:function if it is ever decided to allow for 
default parameter values there.


-- 
Configure bugmail: http://www.w3.org/Bugs/Public/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the QA contact for the bug.
Received on Tuesday, 10 November 2009 01:52:25 UTC

This archive was generated by hypermail 2.4.0 : Friday, 17 January 2020 16:57:29 UTC