[xsl] Conditional sort instruction as parameter within group && Syntactic matter of multilevel grouping | XSLT 2.0 | P2

Subject: [xsl] Conditional sort instruction as parameter within group && Syntactic matter of multilevel grouping | XSLT 2.0 | P2
From: "Fiona Chen anonymousjuly1@xxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Jun 2021 17:33:53 -0000
I can sort on putAmount by exploiting the data engine through API. But I can't
seem to achieve the same sort effect in pure XSLT.
Below is my XSLT module extract as part of the Stage Two implementation:

B B B  <xsl:template match="result">
B B B B B B B  <xsl:variable name="doc" select="document(@uri)"/>
B B B B B B B  <xsl:element name="Trade">
B B B B B B B B B B B  <xsl:element name="documentId"><xsl:value-of
select="$doc/product:requestProduct/product:_metaData/product:docId"/></xsl:e
lement><!-- Line 55 -->
B B B B B B B B B B B  <Justification>
B B B B B B B B B B B B B B B  <xsl:for-each select="descendant::match">
B B B B B B B B B B B B B B B B B B B  <path><xsl:value-of
select="@path"/></path>
B B B B B B B B B B B B B B B B B B B  <highlight><xsl:value-of
select="highlight"/></highlight>
B B B B B B B B B B B B B B B  </xsl:for-each>
B B B B B B B B B B B  </Justification><!-- Line 60 -->
<!-- Line 71:: Traverse XML and JSON -->
B B B B B B B B B B B  <xsl:copy-of
select="incarnation:render-def(fn:normalize-space(@uri))"/>
B B B B B B B  </xsl:element>
B B B  </xsl:template>
Thus,
Question One: The conditional sort is based on the search:highlight, if it is
decimal, sort the putAmount and then incarnate the document. Notice: The
"Rationale" is that currency and amount must be paired. In each
search:snippet, the currency is one search:highlight while amount another. I
would imagine a pure XSLT conditional sort in below manner.
===================================================== B B B  <xsl:param
name="sortAmount">
B B B B B B B  <xsl:for-each select="highlight">
B B B B B B B B B B B  <xsl:sort select="if (normalize-space() castable as
xs:decimal) then descending
B B B B B B B B B B B B B B B  else ()"/>B B B B B B B B B B  B 
B B B B B B B  </xsl:for-each>
B B B  </xsl:param>
B B  B 
B B B  <xsl:template match="result">
B B B B B B B  <xsl:variable name="doc" select="document(@uri)"/>
B B B B B B B  <xsl:element name="Trade">
B B B B B B B B B B B  <xsl:for-each-group select="." group-by="@uri">
B B B B B B B B B B B B B B B  <xsl:call-template name="sort-render">
B B B B B B B B B B B B B B B B B B B  <xsl:with-param name="sortAmt"
select="$sortAmount"/>
B B B B B B B B B B B <!--B B B B B B B B  <xsl:with-param name="uri"
select="current-grouping-key()"/> -->
B B B B B B B B B B B B B B B  </xsl:call-template>
B B B B B B B B B B B  </xsl:for-each-group>
B B B B B B B  </xsl:element>
B B B  </xsl:template>B B B B B B B B  B 
B B  B 
B B B  <xsl:template name="sort-render">
B B B B B B B  <xsl:param name="sortAmt"/>
B <!--B B B B B B  <xsl:param name="uri"/> -->
B B B B B B B  <Justification inDocument="{@uri}">
B B B B B B B B B B B  <xsl:for-each select="descendant::match">
B B B B B B B B B B B B B B B  <path><xsl:value-of select="@path"/></path>
B B B B B B B B B B B B B B B  <highlight><xsl:value-of
select="highlight"/></highlight>
B B B B B B B B B B B  </xsl:for-each>
B B B B B B B  </Justification>
B B B  </xsl:template>
======================================================Above doesn't sort the
decimal search:highlight. The /a.xml is still incarnated first in the Oxygen
(without the data engine support). I don't know if there is a pure XSLT
solution for this. Can the XSLT expert help?
Question Two: Below produces the same result by replacing Line 55 - 60 in my
original XSLT module. Can someone point out if below module is syntactically
correct? (It runs fine in the Oxygen.)
B B B B B B B  <xsl:for-each-group select="." group-by="@uri">
B B B B B B B B B B B  <Justification inDocument="{current-grouping-key()}">
B B B B B B B B B B B B B B B  <xsl:for-each-group select="current-group()"
group-by="snippet">
B B B B B B B B B B B B B B B B B B B  <xsl:for-each
select="descendant::match">
B B B B B B B B B B B B B B B B B B B B B B B  <path><xsl:value-of
select="@path"/></path>
B B B B B B B B B B B B B B B B B B B B B B B  <highlight><xsl:value-of
select="highlight"/></highlight>
B B B B B B B B B B B B B B B B B B B  </xsl:for-each>
B B B B B B B B B B B B B B B  </xsl:for-each-group>
B B B B B B B B B B B  </Justification>
B B B B B B B  </xsl:for-each-group>
Thank you...

Current Thread