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

Re: XPath expression that yields the same result as x

Subject: Re: XPath expression that yields the same result as xsl:for-each-group?
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 30 May 2019 13:20:40 -0000
Re:  XPath expression that yields the same result as  x
On 30.05.2019 15:06, Martin Honnen martin.honnen@xxxxxx wrote:

What XPath expression will yield the desired value for $groups?

<xsl:variable name="groups" select="???" />

Is there an XPath 2.0 expression that can be used?

What kind of sequence type would you expect that XPath expression to return? You can't build sequences of sequences to somehow wrap the items belonging to a group.

So unless you could move to XPath 3.1 with maps and/or arrays I don't
see an XPath type constructed with pure XPath to hold groups. And of
course even there it would be easier and smarter to use XSLT to create
the map or the nested sequence/array or array/sequence structure than to
rely on pure XPath I think.

A pure XPath 3.1 expression to build the groups as a sequence of array(element(row)) would be

let $keys := distinct-values($rows/concat(ARPT__IDENT, '|', TRM__IDENT))
                    return
                      for $key in $keys
                      return array { $rows[$key = concat(ARPT__IDENT,
'|', TRM__IDENT)] }


you could use as



<xsl:template match="Test"> <xsl:variable name="rows" select="row" as="element(row)*"/> <xsl:variable name="groups" as="array(element(row))*" select="let $keys := distinct-values($rows/concat(ARPT__IDENT, '|', TRM__IDENT)) return for $key in $keys return array { $rows[$key = concat(ARPT__IDENT, '|', TRM__IDENT)] }"/> <results> <xsl:for-each select="$groups"> <group> <xsl:sequence select="?*" /> </group> </xsl:for-each> </results> </xsl:template>

https://xsltfiddle.liberty-development.net/jyRYYiQ

But I think using XSLT 2/3 grouping to build a grouping structure, be it
an XML one in XSLT 2 or such a nested sequence of arrays if needed in
XSLT 3 is much easier and probably more efficient anyway.

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.