Re: [xsl] [XPath-2.0] Get the name of type of a node

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: [xsl] [XPath-2.0] Get the name of type of a node

frans.englich (Bugzilla)
On Tuesday 01 November 2005 22:50, Michael Kay wrote:

> There's no function to do this: it's a deliberate omission, because the
> designers wanted to encourage you instead to test
>
> $x instance of TYPE
>
> which means your code isn't dependent on implementation details, for
> example your code shouldn't be affected if a function decides to return an
> unsignedByte when you were expecting an integer. Also, not all types have
> names.
>
> However, for diagnostic purposes, Saxon has an extension function
> saxon:type-annotation(node)
And I of course had to try that. I managed to produce a null pointer
exception.

For the expression(inside xsl:value-of):

                saxon:type-annotation(input)

and the input document "<foo/>", I got:

Tree size: 3 nodes, 0 characters, 0 attributes
Error on line 21 of file:/mnt/data/src/saxon8-5/code.xsl:
  Error in call to extension function {public static java.lang.String
 
net.sf.saxon.functions.Extensions.typeAnnotation(net.sf.saxon.expr.XPathContext,net.sf.saxon.om.NodeInfo)}:
Exception in extension function java.lang.NullPointerException
Transformation failed: Run-time errors were reported

I used:
Saxon 8.5 from Saxonica
Java version 1.4.2_04

Test case attached.


Cheers,

                Frans


code.xsl (621 bytes) Download Attachment
input.xml (8 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

RE: Re: [xsl] [XPath-2.0] Get the name of type of a node

Michael Kay
> > However, for diagnostic purposes, Saxon has an extension function
> > saxon:type-annotation(node)
>
> And I of course had to try that. I managed to produce a null pointer
> exception.
>

It turns out many of the Saxon extension functions throw an NPE if you
supply an empty sequence as the argument. This is because most of them were
written before the mappings for extension functions were changed to map ()
onto a Java null. I've now gone through and made them more robust: most now
return () if you supply (), with some exceptions like saxon:line-number(())
which returns -1.

Michael Kay
http://www.saxonica.com/




-------------------------------------------------------
SF.Net email is sponsored by:
Tame your development challenges with Apache's Geronimo App Server. Download
it for free - -and be entered to win a 42" plasma tv or your very own
Sony(tm)PSP.  Click here to play: http://sourceforge.net/geronimo.php
_______________________________________________
saxon-help mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help