[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Cannot mix nodes and atomic values - how comes?

Subject: Re: Cannot mix nodes and atomic values - how comes?
From: "Michael Kay mike@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 11 Nov 2016 11:21:51 -0000
Re:  Cannot mix nodes and atomic values - how comes?
> On 11 Nov 2016, at 10:30, Michael MC<ller-Hillebrand mmh@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
>
> Hi experts,
>
> We ran into an error that made me think about the idea of mixed data types
in sequences. Take this instance:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <bars>
> <bar foo="x"/>
> <bar/>
> </bars>
>
> We need to process all <bar> and want to have a default value if @foo is not
present. When trying this XPath:
>
> for $i in //bar/(@foo, 'no-foo')[1] return $i
>
> we get the error "XPath failed due to: Cannot mix nodes and atomic values in
the result of a path expression"

This is because the "/" operator is defined to remove duplicates and sort into
document order if the expression delivers nodes, but not if it delivers atomic
values. If it delivers a mixture, the semantics would become very unclear.
Hence the need for the "!" operator in 3.0.

>
> When building the XPath the following way it runs fine and creates a
sequence of an attribute and a string:
>
> for $b in //bar return for $i in $b/(@foo, 'no-foo')[1] return $i

Here each evaluation of "/" delivers either all-nodes, or all-atomic-values.
>

Michael Kay
Saxonica

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.