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

Best practice for group-adjacent with quasi-null group

Subject: Best practice for group-adjacent with quasi-null grouping key?
From: "David Sewell dsewell@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 26 Apr 2016 18:39:35 -0000
 Best practice for group-adjacent with quasi-null group
(Following assumes XSLT 2.0)

I don't use the @group-adjacent form of <xsl:for-each-group> often enough to be a master of it. I just ran into the problem that an empty sequence is not allowed as the result of evaluating the group-adjacent expression. Given data like

<contributor role="author">Joe Jones</contributor>
<contributor role="author">Mary Mitchell</contributor>
<contributor role="editor">Betty Berkeley</contributor>
<contributor role="editor">Peter Parker</contributor>

my first instinct was to use
  <xsl:for-each-group select="contributor" group-adjacent="@role">

but I got a run-time error because the @role is not always present in my data. So I revised to

  <xsl:for-each-group select="contributor" group-adjacent="if (@role)
    then string(@role) else 'false'">

which give the desired results. But is there a better general strategy, maybe using boolean false() as the grouping value, and then being sure to cast current-grouping-key() as a string whenever a string comparison is needed?

(I see that XSLT 3.0 adds the @composite option to xsl:for-each-group in which case the group-adjacent expression is allowed to evaluate as empty sequence, but I'm stuck with a version 2.0 processor in my use case.)

David

--
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4314 USA
Email: dsewell@xxxxxxxxxxxx   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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

Buy Stylus Studio Now

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