Sorry, I was confused and confusing. The function that computes the sort key of a node takes a node as input and produces an atomic value as output. So you should try:

<xsl:function name="udf:expression" as="xs:string">
      <xsl:param name="expr" as="xs:string"/>
      <xsl:param name="context-item" as="node()"/>

Then if $expr is @price, the result of xsl:evaluate will be an attribute node, which will automatically be atomized and converted to a string by virtue of the function calling rules, so the actual result of evaluating the sort key is a string.

Michael Kay
Saxonica

On 02/04/2012 21:46, David Rudel wrote:
Hi Michael,

Now I must admit that your response threw me for a loop. I would think that the argument type for the function should be node() because it is being passed the context-item. I clearly don't know my ear from my elbow here. I should go buy your book.

When I tried using

   <xsl:function name="udf:expression">
      <xsl:param name="expr" as="xs:string"/>
      <xsl:param name="context-item" as="xs:anyAtomicType"/>
      <xsl:for-each select="$context-item">
        <xsl:evaluate xpath="$expr"/>
      </xsl:for-each>
    </xsl:function>

I get the following error message:

Error on line 1 of sandbox.xsl:
  XPTY0020: The context item for axis step attribute::attribute('':price) is not a node
  at udf:expression() (file:/C:/Users/Drudel/Desktop/OLoLSmallTest/sandbox.xsl#17)
  at udf:expression() (file:/C:/Users/Drudel/Desktop/OLoLSmallTest/sandbox.xsl#17)
Transformation failed: Run-time errors were reported

When instead I try

    <xsl:function name="udf:expression">
      <xsl:param name="expr" as="xs:string"/>
      <xsl:param name="context-item" as="node()"/>
      <xsl:for-each select="$context-item">
        <xsl:evaluate xpath="$expr"/>
      </xsl:for-each>
    </xsl:function>

I get what appears to be the same error message as earlier:

java.lang.ClassCastException: net.sf.saxon.value.SingletonItem cannot be cast to net.sf.saxon.value.AtomicValue
    at com.saxonica.functions.extfn.Sort$SortCall$1.evaluateSortKey(Sort.java:78)
    at net.sf.saxon.expr.sort.SortedIterator.buildArray(SortedIterator.java:232)
    at net.sf.saxon.expr.sort.SortedIterator.doSort(SortedIterator.java:248)
    at net.sf.saxon.expr.sort.SortedIterator.next(SortedIterator.java:133)
    at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:83)
    at net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(CopyOf.java:475)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:212)
    at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1034)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1957)
    at net.sf.saxon.Controller.transform(Controller.java:1803)
    at net.sf.saxon.Transform.processFile(Transform.java:985)
    at net.sf.saxon.Transform.doTransform(Transform.java:619)
    at net.sf.saxon.Transform.main(Transform.java:73)
Fatal error during transformation: java.lang.ClassCastException: net.sf.saxon.value.SingletonItem cannot be cast to net.sf.saxon.value.AtomicValue


I'm attaching the first version of my xsl and the xml source.
Thanks for your continued attention on this.

-David

On Mon, Apr 2, 2012 at 9:33 PM, Michael Kay <mike@saxonica.com> wrote:
On the face of it, I suspect that (a) the function passed to sort() in the second argument didn't declare its argument type as xs:anyAtomicType (or a subtype thereof), and (b) the implementation of saxon:sort() fails to detect this. This would be a bug, but as a workaround, try declaring the argument type for the function.

A repro that we can use to test the bug clearance would be appreciated.

Michael Kay
Saxonica


On 02/04/2012 19:14, David Rudel wrote:
Hi Michael,

The error is shown below.

I get the same error when I call from the command line directly using java -jar [dir]/saxon9pe.jar

FWIW, I think I'm going to be able to talk my company into upgrading to either use oXygen or Stylus Studios IDE.

java.lang.ClassCastException: net.sf.saxon.value.SingletonItem cannot be cast to net.sf.saxon.value.AtomicValue
    at com.saxonica.functions.extfn.Sort$SortCall$1.evaluateSortKey(Sort.java:78)
    at net.sf.saxon.expr.sort.SortedIterator.buildArray(SortedIterator.java:232)
    at net.sf.saxon.expr.sort.SortedIterator.doSort(SortedIterator.java:248)
    at net.sf.saxon.expr.sort.SortedIterator.next(SortedIterator.java:133)
    at net.sf.saxon.expr.ItemMappingIterator.next(ItemMappingIterator.java:83)
    at net.sf.saxon.expr.instruct.CopyOf.processLeavingTail(CopyOf.java:475)
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:212)
    at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1034)
    at net.sf.saxon.Controller.transformDocument(Controller.java:1957)
    at net.sf.saxon.Controller.transform(Controller.java:1803)
    at net.sf.saxon.Transform.processFile(Transform.java:985)
    at net.sf.saxon.Transform.doTransform(Transform.java:619)
    at net.sf.saxon.Transform.main(Transform.java:73)
Fatal error during transformation: java.lang.ClassCastException: net.sf.saxon.value.SingletonItem cannot be cast to net.sf.saxon.value.AtomicValue


On Mon, Apr 2, 2012 at 7:56 PM, Michael Kay <mike@saxonica.com> wrote:

>
> I had tried passing in a function but could not figure out how to
> reference the context item. And that leads me to a follow-up question
> that displays my ignorance:  where you "?" what should I put?
It was intended to be a literal '?'. saxon:sort expects the second
argument to be a one-argument function. If you have a two-argument
function f(a, b), then f('abcd', ?) represents a one-argument function:
if we call this one-argument function g($x) then the value of g($x) is
the value of f('abcd', $x). This construct is called 'partial function
application'.
>
>
>
> I then decided to try using a literal ?, and that threw a java error.
>
>
What was the error?

Michael Kay
Saxonica

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.


------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help 

------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help



--

"A false conclusion, once arrived at and widely accepted is not dislodged easily, and the less it is understood, the more tenaciously it is held." - Cantor's Law of Preservation of Ignorance.


------------------------------------------------------------------------------
Better than sec? Nothing is better than sec when it comes to
monitoring Big Data applications. Try Boundary one-second 
resolution app monitoring today. Free.
http://p.sf.net/sfu/Boundary-dev2dev


_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help