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

RE: Complex group-by with saxon:evaluate?

Subject: RE: Complex group-by with saxon:evaluate?
From: Moritz Ringler <xsl-list@xxxxxxxxxxxxxxxxx>
Date: Wed, 27 Sep 2006 10:55:47 +0200
for each groupby xml
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)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Cast Your Vote

We need your help – Vote for DataDirect XML Products!

  • Best SOA or XML site

Winners and finalists announced at SOA World Conference in November.

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-2007 All Rights Reserved.