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

Subject: Re: [xsl] Conditional sort instruction as parameter within group && Syntactic matter of multilevel grouping | XSLT 2.0 | P2
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 6 Jun 2021 21:39:41 -0000
Fiona, I'm afraid you really aren't making yourself very clear.

It would be much easier if you showed us a source document and a desired
result document.

You've shown us code like

> <xsl:for-each select="highlight">
> >              <xsl:sort select="if (normalize-space() castable as
> > xs:decimal) then descending
> >                  else ()"/>
> >          </xsl:for-each>

that makes very little sense:

* There's no body to the xsl:for-each, so it produces no output

* 'normalize-space() castable as xs:decimal` means exactly the same as '.
castable as xs:decimal'

* 'descending' here means child::descending, that is you're sorting on the
value of a child element named 'descending'. Is that what you intended? It
seems unlikely, but without seeing a source document we really can't tell. If
you intended to sort in descending order, then that must be decided for the
sort as a whole, not for each individual sort key.

You state the requirement as:

> Question One is how to sort <search:highlight> when its value is decimal (
string is ignored ),"descending" or "ascending", in PURE XSLT.

and you've tried to explain the data by telling us:

> <search:highlight> contains both string( /*:putCurrencyAmount/*:currency)
and decimal (/*:putCurrencyAmount/*:amount) value in the same parent element
(search:result/search:snippet).

but I just don't understand either sentence. It would be so much easier if you
showed us some sample XML input and desired output.

Michael Kay
Saxonica


> On 6 Jun 2021, at 22:00, Fiona Chen anonymousjuly1@xxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> The logic is to sort on the <search:highlight>:
>
> <search:highlight> contains both string( /*:putCurrencyAmount/*:currency)
and decimal (/*:putCurrencyAmount/*:amount) value in the same parent element
(search:result/search:snippet).  "sortAmount" is supposed to sort  /*:amount
(in this search result, only two amount: 26000000 , 38500000)  not the
/*:currency.
>
> As explained, it is merely my imagination to produce <xsl:param
name="sortAmount"> : WITH or WITHOUT parameter, WITH or WITHOUT group-by, WITH
or WITHOUT
> "see any further sorting", WITH or WITHOUT anything...I am NOT able to sort
the amount using XSLT alone, it consistently renders the document with
lower-amount first even I specify "descending".
>
> As you can see, with the help of the data engine, the document with
higher-amount stays on top in the UI.
>
> Question One is how to sort <search:highlight> when its value is decimal (
string is ignored ),"descending" or "ascending", in PURE XSLT.
>
> Question Two: I mentioned it is "Syntactic matter". Whenever I use
"xsl:for-each-group" or "current-grouping-key()", the data engine failed
miserably...Before I claim it is the bug of the data engine (I understand it
can't digest XSLT 3.0 and "current-grouping-key" is ONLY available in XSLT), I
want to ensure it is not a syntactic problem.
> I can't help wondering how to expand the XSLT 2.0+ capabilities within the
data engine...
>
>
> On Sunday, June 6, 2021, 3:32:14 p.m. EDT, Martin Honnen
martin.honnen@xxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
>
> On 06.06.2021 19:34, Fiona Chen anonymousjuly1@xxxxxxxx
<mailto:anonymousjuly1@xxxxxxxx> wrote:
> > 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.
> >
> > =====================================================
> >      <xsl:param name="sortAmount">
> >          <xsl:for-each select="highlight">
> >              <xsl:sort select="if (normalize-space() castable as
> > xs:decimal) then descending
> >                  else ()"/>
> >          </xsl:for-each>
> >      </xsl:param>
>
> What kind of value is sortAmount supposed to represent, a sequence of
> sort values like the amount, a sequence of sort orders like "descending"?
>
> >
> >      <xsl:template match="result">
> >          <xsl:variable name="doc" select="document(@uri)"/>
> >          <xsl:element name="Trade">
> >              <xsl:for-each-group select="." group-by="@uri">
> >                  <xsl:call-template name="sort-render">
> >                      <xsl:with-param name="sortAmt"
select="$sortAmount"/>
> >             <!--         <xsl:with-param name="uri"
> > select="current-grouping-key()"/> -->
> >                  </xsl:call-template>
> >              </xsl:for-each-group>
> >          </xsl:element>
> >      </xsl:template>
> >
> >      <xsl:template name="sort-render">
> >          <xsl:param name="sortAmt"/>
> >   <!--       <xsl:param name="uri"/> -->
> >          <Justification inDocument="{@uri}">
> >              <xsl:for-each select="descendant::match">
> >                  <path><xsl:value-of select="@path"/></path>
> >                  <highlight><xsl:value-of
select="highlight"/></highlight>
> >              </xsl:for-each>
> >          </Justification>
> >      </xsl:template>
>
> Can you explain where you want to sort? You create a parameter named
> sortAmount and pass it on as sortAmt but I do not even see any further
> sorting there that uses sortAmt.
>
>
>
> XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
> EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by
email <>)

Current Thread