xsl-list
[Top] [All Lists]

Re: [xsl] Best practice for group-adjacent with quasi-null grouping key?

2016-04-26 13:47:56
Yes, that seems like the most elegant solution, since for my purposes an empty string and a null attribute are synonymous. Thanks!

On Tue, 26 Apr 2016, Martin Honnen martin(_dot_)honnen(_at_)gmx(_dot_)de wrote:

On 26.04.2016 20:39, David Sewell dsewell(_at_)virginia(_dot_)edu wrote:
(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 would be inclined to simply use

  group-adjacent="string(@role)"

unless you could have both <el role="">...</el> and <el>...</el> and
would need to distinguish them.


---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus



--
David Sewell, Editorial and Technical Manager
ROTUNDA, The University of Virginia Press
PO Box 400318, Charlottesville, VA 22904-4314 USA
Email: dsewell(_at_)virginia(_dot_)edu   Tel: +1 434 924 9973
Web: http://rotunda.upress.virginia.edu/
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>