Saxon error "XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:string"

12,872

According to http://www.w3.org/TR/xslt20/#variable-values, "If the variable-binding element has empty content and has neither a select attribute nor an as attribute, then the supplied value of the variable is a zero-length string.".

So you need to change that, for instance by doing <xsl:variable name="patterns" select="()"/> to bind an empty sequence as the variable value.

Share:
12,872

Related videos on Youtube

Dimitre Novatchev
Author by

Dimitre Novatchev

I was the first (of what is now the "all golds XML club") to hold all of these: the gold badge in XSLT, the gold badge in XML and the gold badge in XPath. Some of the more interesting things I've been doing can be found via these links:      Training course on "XSLT 2 and 1 Foundations", -- 12 modules, 8:45 hours      the FXSL page,      my Finger Tree implementation in C#      My Original XPath Visualizer hosted by Lars Huttar      the Extreme Markup Conf. presentation on FXSL 2.0      My Balisage 2013 paper "Programming in XPath 3.0",       and the PPT presentation      My Blog      Follow me on Twitter

Updated on September 03, 2022

Comments

  • Dimitre Novatchev
    Dimitre Novatchev over 1 year

    I have an XSL program which in turn generates an XSL program, which depending on the input might look like this:

    <xsl:variable name="patterns"/> <!--empty in this particular case-->
    
    <xsl:template name="token">
        <xsl:for-each select="$patterns/pattern">
    ...
    

    When I then run the generated stylesheet, Saxon, bless its heart, is apparently doing some kind of static analysis and complains:

    XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:string
    

    and won't even compile the stylesheet.

    My workaround was to generate a dummy element in the $patterns nodeset, but is there any cleaner approach here, or way to suppress the compile error?

  • Admin
    Admin over 11 years
    Thanks for the info, problem solved with an as=node()* attribute.
  • Admin
    Admin over 11 years
    Thanks. The problem is that the XSLT is being generated on the fly, by something that looks like <tns:variable name="patterns"> <xsl:apply-templates select="terminal/any"/> </tns:variable> (where tns is a namespace prefix mapped to xsl on output), so I don't know in advance whether the variable will be empty or not, which is why the as attribute was the perfect solution for me, seeing as how I'm using XSLT 2.0.