This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Evaluating parameter in <xsl:when> vs evaluating parameter in <xsl:sort>


Hi Roelf,

> The solution turned out to be:
> ..
> <xsl:when test="$sortParameter='name'" >
>
>           <xsl:for-each select="query">
>           <xsl:sort select="xalan:evaluate($sortParameter)"
> order="ascending"/>

Within the xsl:when, you *know* that the $sortParameter has the value
'name', so there's no point evaluating it dynamically (which is costly
in terms of processing) -- you can just fix the path used in the
xsl:sort instead:

  <xsl:when test="$sortParameter = 'name'">
    <xsl:for-each select="query">
      <xsl:sort select="name" />
      ...
    </xsl:for-each>
  </xsl:when>

> Why is it that in the <when> & <copy> tags I can call it simply but
> in the sort tag it needs the xalan:evaluate() ?

In the XPath expressions on the xsl:when and xsl:copy-of elements,
you're wanting to treat $sortParameter as a string and either test or
output the value of that string.

In the XPath expression on the xsl:sort, you're wanting to evaluate
the string "name" as the XPath expression "name", which selects the
value of the name element child of the context (query) element. If you
selected just the value of the $sortParameter, as in:

  <xsl:sort select="$sortParameter" />

then it would be equivalent to:

  <xsl:sort select="'name'" />

which would mean that you'd be sorting each query by the string
'name' -- the string 'name' is always the string 'name', so they'd
each get the same value to be sorted by, and they would sort in their
normal order.

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]