xsl-list
[Top] [All Lists]

RE: [xsl] Complex group-by with saxon:evaluate?

2006-09-27 01:56:03
Michael Kay wrote:
Firstly, if only the element name varies, then you don't need xx:evaluate(),
you can use group-by="*[name()=$param]".

Secondly, if you tried something and it didn't work, then we need to know
exactly what you tried and exactly how it failed.
Ok, so here's the whole relevant xsl snippet
01: <ul>
02: <xsl:for-each-group select="bibtex:entry"
group-by="tokenize(normalize-space(*/bibtex:refgroup),' *; *')">
03:     <xsl:sort select="current-grouping-key()" order="ascending"/>
04:       <li><xsl:value-of select="current-grouping-key()"/></li>
05:   </xsl:for-each-group>
06: </ul>

Each bibtex:refgroup node contains one or more entries separated by ';'.
The entries may contain newlines that do not mark a logical separation,
which is why I put the 'normalize-space'. As stated the above xsl works
as expected by producing a list of refgroups.

Now, to my attempts to dynamically replayce bibtex:refgroup with another
node:
I put
  <xsl:param name="groupby">bibtex:refgroup</xsl:param>
immediately after the xsl:output tag (as an immediate child of
xsl:transform).
And added another line
  07: <xsl:value-of select="$groupby"/>

A:
  Now, I first replaced line 2 above with:
    02: <xsl:for-each-group select="bibtex:entry"
group-by="tokenize(normalize-space(*[name()=$groupby]),' *; *')">
  The stylesheet compiles alright, but the result of the transformation is:
Result:
    <ul></ul>
    bibtex:refgroup

B:
  line 2 is simplified to
   02: <xsl:for-each-group select="bibtex:entry"
group-by="*[name()=$groupby]">
  Result: same as (A)

C:
(with saxon:evaluate)
  I added 
    xmlns:saxon="http://saxon.sf.net/"; exclude-result-prefixes="bibtex
fn saxon"
  to my xsl:transform tag, and changed line 2 above to
    02: <xsl:for-each-group select="bibtex:entry"
group-by="tokenize(normalize-space(saxon:evaluate('*/$groupby')),' *; *')">
Result:
  Compilation of the stylesheet fails with:
    Error at xsl:for-each-group on line xx[=02] of file:transform.xsl:
      Static error in XPath expression supplied to saxon:evaluate:
Undeclared variable in a standalone expression

D:
  Changed line 2 to
    02: <xsl:for-each-group select="bibtex:entry"
group-by="tokenize(normalize-space(saxon:evaluate('*/$p1', $groupby)),'
*; *')">
Result:
    <ul>
    <li>bibtex:refgroup</li>
    </ul>
    bibtex:refgroup

E:
  Changed line 2 to
    02: <xsl:for-each-group select="bibtex:entry"
group-by="saxon:evaluate('*/$p1', $groupby)">
Result: same as (D)




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>