Interest Ask. Suppose your XPath input expression set satisfies some limiting reasons, for example, if there is X / article [2], then also (preceding it) X / article [1]. And let at the moment a part of the namespace will stand on one side.
Letβs release the XSLT 2.0 solution: we will start by typing in the form
<paths> <path value="1">/create/article[1]/id</path> <path value="bar">/create/article[1]/description</path> </paths>
and then we turn it into
<paths> <path value="1"><step>create</step><step>article[1]</step><step>id</step></path> ... </paths>
Now we will call a function that performs grouping in the first step, and calls itself recursively for grouping in the next step:
<xsl:function name="f:group"> <xsl:param name="paths" as="element(path)*"/> <xsl:param name="step" as="xs:integer"/> <xsl:for-each-group select="$paths" group-by="step[$step]"> <xsl:element name="{replace(current-grouping-key(), '\[.*', '')}"> <xsl:choose> <xsl:when test="count(current-group) gt 1"> <xsl:sequence select="f:group(current-group(), $step+1)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="current-group()[1]/@value"/> </xsl:otherwise> </xsl:choose> </xsl:element> </xsl:for-each-group> </xsl:function>
This is untested, and there may be details that you need to configure in order to make it work. But I think the basic approach should work.
Part of the namespace might be best resolved by preprocessing the path list to add a namespace attribute for each step element; this can then be used in the xsl: element statement to put the element in the correct namespace.
Michael kay
source share