On 09/06/2011 14:07, Jayarajan, Divya wrote:
Attached are the files that throws this particular exception.

The function java:com.sonicsw.xq.service.xform.HeaderExtension.dateFormatAsNumber had me confused for a minute - despite its name, it's an XSLT function and not a Java function.

It's not returning a number, it's returning a sequence of text nodes. Each <xsl:value-of> instruction creates a text node, and there's nothing in the spec of xsl:function to say these text nodes are concatenated.

The quickest fix is to wrap the whole body of the function in another xsl:value-of, like this:

<xsl:function name="....">
<xsl:param ...>
<xsl:value-of>
    <xsl:if ...
    <xsl:if ...
</xsl:value-of>
</xsl:function>

This outer xsl:value-of will do the concatenation.

I'd recommend a more thorough refactoring to bring your code more into line with XSLT 2.0 good practice:

* declare the types of all your variables and parameters and the result type of your functions using an "as" attribute (this will give you clearer error messages)

* don't treat strings as numbers or numbers as strings: do explicit conversions when needed

* Change this kind of construct

<xsl:variable name="day">
<xsl:value-of select="substring($DateTime,1,2)"/>
</xsl:variable>

to

<xsl:variable name="day" select="substring($DateTime,1,2)"/>

(actually that's good practice even in XSLT 1.0)

* deliver the result of the function using xsl:sequence

<xsl:sequence select="concat($day, $hh, $mm, $ss)"/>

But actually, you can replace the whole function with something like

<xsl:function name="XQHeaderFunc:dateFormatAsNumber" as="xs:string">
  <xsl:param name="in" as="xs:string"/>
  <xsl:analyze-string regex="(..)-(...)-(....) (..):(..):(..)">
    <xsl:matching-substring>
     <xsl:sequence select="concat(regex-group(3), f:month(regex-group(2)), regex-group(1), regex-group(4), regex-group(5), regex-group(6))"/>
    </xsl:mathing-substring>
  </
</

<xsl:function name="f:month" as="xs:string">
  <xsl:param name="monthName" as="xs:string"/>
  <xsl:sequence select="format-number(index-of(('JAN', 'FEB', ...), $monthName), '00')"/>
</xsl:function>

I'm afraid exploring the history to work out when the W3C draft spec was changed and when the change was implemented in Saxon is unlikely to be a productive exercise. You've got a bit of a problem here in dealing with old code that was written to a spec that wasn't stable.

Michael Kay
Saxonica
 
Thanks,
Divya


From: Michael Kay [mailto:mike@saxonica.com]
Sent: Thursday, June 09, 2011 6:30 PM
To: saxon-help@lists.sourceforge.net
Subject: Re: [saxon] Exception with Sort in XSLT using Saxon8.9

On 09/06/2011 12:29, Jayarajan, Divya wrote:

I'm sorry, you'll have to provide more information. And even then, I may not be able to help since 8.9 is a rather old release.

The error message means what it says. It's possible that earlier releases didn't enforce this rule, since it's new to XSLT 2.0.

When you say that your extension function returns "a number", what exactly do you mean? What is the Java method signature?

Michael Kay
Saxonica

Hi,
 
I am getting 'net.sf.saxon.trans.DynamicError: A sequence of more than one item is not allowed as the @select attribute of xsl:sort' error with sort function in Saxon8.9.
This is the code snippet in XSLT:
<xsl:sort select="XQHeaderFunc:dateFormatAsNumber(LastUpdateDateGMT)" data-type="number" order="descending"/>
The XQHeaderFunc:dateFormatAsNumber() returns a number.
This is working fine with Saxon8.4.Is there anything changed later releases.
 
Thanks,
Divya
 
 
 
------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------ EditLive Enterprise is the world's most technically advanced content authoring tool. Experience the power of Track Changes, Inline Image Editing and ensure content is compliant with Accessibility Checking. http://p.sf.net/sfu/ephox-dev2dev
_______________________________________________ saxon-help mailing list archived at http://saxon.markmail.org/ saxon-help@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/saxon-help