Project

Profile

Help

typeswitch question

Added by Anonymous almost 19 years ago

Legacy ID: #3287712 Legacy Poster: marcvc (marcvc)

Michael, consider the following query: let $node := <e a=""/>/@* return typeswitch($node) case $a as text() return "text()" case $a as element() return "element()" case $a as document-node() return "document-node()" case $a as processing-instruction() return "processing-instruction()" case $a as comment() return "comment()" case $a as attribute() return "attribute()" default return () With Saxon 8.5, and also previous versions, I get the following error: XPTY0004: Required item type of value of variable $a is text(); supplied value has itemtype attribute() Thanks, Marc


Replies (2)

RE: typeswitch question - Added by Anonymous almost 19 years ago

Legacy ID: #3292757 Legacy Poster: Michael Kay (mhkay)

This seems to be a recurrence of a problem (or a closely related problem) that occurred in previous releases when a branch of a typeswitch can be ruled out statically. There's a simple fix: Fix: in QueryParser, change line 1840 v.setRequiredType(type); to v.setRequiredType(SequenceType.ANY_SEQUENCE); but this seems to leave the system to do all the work at run-time, so I'm investigating whether it's possible to do any better. Michael Kay

RE: typeswitch question - Added by Anonymous almost 19 years ago

Legacy ID: #3299064 Legacy Poster: Michael Kay (mhkay)

It turns out that to do more of the evaluation at compile time would require an inference that the cardinality of <e a=""/>/@* is exactly-one, and that's beyond the current state of the art. (It could be done by evaluating the element constructor and path expression at compile time, but that would require analysis to prove that the context isn't identity-sensitive, i.e. that the query doesn't create multiple elements and expect them to be distinct). MK

    (1-2/2)

    Please register to reply