XPATH 2.0 "FOTY0012: The node has no typed value"

I have a simple input XML file:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<rootelement xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="index.xsd">
    <compound>
        <name>FooBar</name>
        <member>
            <name>Something</name>
        </member>
    </compound>
</rootelement>

Open in new window

and a simple schema file to go with it index.xsd:
<?xml version='1.0' encoding='utf-8' ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <xs:element name="rootelement" type="RootType"/>

  <xs:complexType name="RootType">
    <xs:sequence>
      <xs:element name="compound" type="CompoundType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="CompoundType">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="member" type="MemberType"/>
    </xs:sequence>
  </xs:complexType>

  <xs:complexType name="MemberType">
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>

</xs:schema>

Open in new window

and a simple XSLT 2.0 transformation file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
  
  <xsl:template match="/">
    <xsl:apply-templates select="rootelement" />
  </xsl:template>
  
  <xsl:template match="rootelement">
    <xsl:copy-of select="." />
    <xsl:value-of select="." />

  </xsl:template>
  
</xsl:stylesheet>

Open in new window

which when I run the transform on the input XML file, I get the error:

"FOTY0012: The node <rootelement> has no typed value"

when it hits the line: <xsl:value-of select="." />

Is there a way I can modify the schema file index.xsd so I don't get this error?

The closest to an explanation I could find is:
XML Path Language (XPath) 2.0
2.5.2 Typed Value and String Value

http://www.w3.org/TR/xpath20/#id-typed-value

However, I'm still not clear on why it doesn't just grab the text and return it, like XPATH 1.0 does, or like it does if I don't supply the schema.
deleydAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
Geert BormansInformation ArchitectCommented:
The problem is that your output is no  XML
(you failed to tell us how you run the XSLT actually)

but the copy-of copies does a deep copy of the rootelement, so you open en close a rootelement named <rootelement> in your output
after that you do a value-of, copying all the text nodes from your source, after the root element has been closed
You don't need to change the schema (the source is valid against the schema), you need to change the XSLT
0
 
Geert BormansInformation ArchitectCommented:
Well, partially ignore the above, it is true that the result is not well formed XML, but the error happens before serialization

xsl:value-of does atomisation
and the schema dictates that <rootelement> only has element content only
see here
https://www.w3.org/TR/xpath20/#id-atomization
that is done by implicitely executing fn:data()
https://www.w3.org/TR/xquery-operators/#func-data

I don't think you should change the schema... the content of your root is element only, so says the schema
you simply should not pass a value-of on the node with element only content

you could do this
        <xsl:value-of select=".//text()" />
 which has the same effect in the XSLT2
but then the atomisation does not break on the untyped node

If you would change the schema, all you can do is set the content type to mixed
    <xs:complexType name="RootType" mixed="true">
then the XSLT won't break
but you make the not significant whitespace into significant whitespace... your choice
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
Geert BormansInformation ArchitectCommented:
Both suggested solutions
- change the value-of select attribute
- set the complex type of the document root to mixed
work on both Saxon EE and the Altova engine
0
 
deleydAuthor Commented:
Thank you that's exactly what I needed to know.

(I suspect this may be code that was originally XSLT 1.0 ported to 2.0 and then handed to me.)
0
 
Geert BormansInformation ArchitectCommented:
welcome
yes, porting 1.0 code to 2.0 has a lot of potential side effects
it could take a fair amount of rework, specially because of the type system
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.