Hi Martin,
    These Xalan XSLT 3.0 implementation issues have been solved
somewhat, and the code improvements have been committed to Xalan's
xslt 3.0 development branch.

The following XSLT 3.0 stylesheet is working fine now with Xalan-J's
xslt 3.0 development branch,

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                         xmlns:map="http://www.w3.org/2005/xpath-functions/map";
                         exclude-result-prefixes="map"
                         expand-text="yes"
                          version="3.0">

   <xsl:output method="xml" indent="yes"/>

   <xsl:variable name="map-sequence1" select="(map { 'name' : 'foo',
'value' : 3 },

                                              map { 'name': 'bar',
'value' : 2 })" as="map(*)*"/>

   <xsl:template match="/">
        <result>
              <xsl:variable name="sorted-map-sequence1" as="map(*)*">
                   <xsl:perform-sort select="$map-sequence1">
                       <xsl:sort select="map:get(.,'value')"/>
                   </xsl:perform-sort>
              </xsl:variable>
              <xsl:for-each select="$sorted-map-sequence1">
                   <item>
                       <name>{map:get(.,'name')}</name>
                       <value>{map:get(.,'value')}</value>
                    </item>
               </xsl:for-each>
           </result>
   </xsl:template>

</xsl:stylesheet>

An XPath syntax like ?value is yet not supported by Xalan's XSLT 3.0
development branch. We need to use XPath function calls like map:get
as of now.

On Wed, Dec 17, 2025 at 1:53 PM Martin Honnen <[email protected]> wrote:
> I have seen that support for xsl:perform-sort has landed on the Apache
> Xalan XSLT 3.0 development branch.
>
> I have tried to write a test case that sorts a sequence of XPath 3.1/XDM
> 3.1 maps, it works fine with Saxon but gives an error with Xalan:
>
> warning: VariableReference given for variable out of context or without
> definition!  Name = sorted-map-sequence1; SystemID: file:///sheet.xsl;
> Line#: 22; Column#: 52
> fatalError: java.lang.NullPointerException; SystemID: file:///sheet.xsl;
> Line#: 32; Column#: 15
>
> Test:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>    version="3.0"
>    xmlns:xs="http://www.w3.org/2001/XMLSchema";
>    xmlns:map="http://www.w3.org/2005/xpath-functions/map";
>    xmlns:array="http://www.w3.org/2005/xpath-functions/array";
>    exclude-result-prefixes="#all"
>    expand-text="yes">
>
>    <xsl:param name="map-sequence1" as="map(*)*" select="(map { 'name' :
> 'foo', 'value' : 3 }, map { 'name': 'bar', 'value' : 2 })"/>
>
>    <xsl:variable name="sorted-map-sequence1" as="map(*)*">
>      <xsl:perform-sort select="$map-sequence1">
>        <xsl:sort select="?value"/>
>      </xsl:perform-sort>
>    </xsl:variable>
>
>    <xsl:output method="xml" indent="yes"/>
>
>    <xsl:template match="/*">
>      <xsl:copy>
>        <xsl:for-each select="$sorted-map-sequence1">
>          <item>
>            <name>{?name}</name>
>            <value>{?value}</value>
>          </item>
>        </xsl:for-each>
>      </xsl:copy>
>    </xsl:template>
>
>    <xsl:template match="/">
>      <xsl:copy>
>        <xsl:apply-templates/>
>        <xsl:comment>Run with {system-property('xsl:vendor')} at
> {current-dateTime()}</xsl:comment>
>      </xsl:copy>
>    </xsl:template>
>
> </xsl:stylesheet>
>
> Result with Saxon is e.g.
>
> <?xml version="1.0" encoding="UTF-8"?>
> <root>
>     <item>
>        <name>bar</name>
>        <value>2</value>
>     </item>
>     <item>
>        <name>foo</name>
>        <value>3</value>
>     </item>
> </root>
> <!--Run with Saxonica at 2025-12-17T08:17:26.89Z-->
>
>


-- 
Regards,
Mukul Gandhi

Reply via email to