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

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

XSD 1.0 document:
bars.xsd
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">

    <xs:element name="bars">
        <xs:complexType>
            <xs:sequence>
                <xs:element name="bar" minOccurs="1" maxOccurs="unbounded">
                    <xs:complexType>
                        <xs:attribute name="foo" type="xs:string"
default="def-val"/>
                    </xs:complexType>
                </xs:element>
            </xs:sequence>
        </xs:complexType>
    </xs:element>

</xs:schema>

XSLT 2.0 (schema aware) document:
bars.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="2.0">

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

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

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

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

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.