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

Subject: Re: [xsl] Cannot mix nodes and atomic values - how comes?
From: "Mukul Gandhi gandhi.mukul@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 12 Nov 2016 13:06:48 -0000
I've tried to reproduce your question using my own sample, which is below.

XML document:
<?xml version="1.0" encoding="UTF-8"?>
    <bar foo="x"/>

XSD 1.0 document:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="";>

    <xs:element name="bars">
                <xs:element name="bar" minOccurs="1" maxOccurs="unbounded">
                        <xs:attribute name="foo" type="xs:string"


XSLT 2.0 (schema aware) document:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="";

    <xsl:output method="xml" indent="yes" />

    <xsl:import-schema schema-location="bars.xsd" />
    <xsl:template match="bars">
           <xsl:for-each select="bar/@foo">
               <att><xsl:value-of select="."/></att>

When I do an XSLT transformation of bars.xml with bars.xsl, I get the
following output:
<?xml version="1.0" encoding="UTF-8"?>

The idea I've illustrated is, getting a default value of an attribute from
an XSD Schema document (which is accessible from an XSLT stylesheet in a
schema aware transformation scenario).

I'm using Saxon-EE embedded in oXygen XML Developer.

with best regards,
Mukul gandhi

On 11 November 2016 at 16:00, 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"
> 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
> What is the difference? Did I miss something in the specification?
> Thanks,
> - Michael
> (Tested with Saxon 9.2/Kernow, 9.6/OxygenXML)

Current Thread