Nicholas Saunders
Nicholas Saunders

Reputation: 764

xslt transform error: XTSE0010: Element xsl:mode must not appear directly within xsl:stylesheet

I'm looking to change nodes from one value to another. Not the value of the node, but the name of the node. Not the content inside the tags.

Wikipedia would say "tags" as:

Tag A tag is a markup construct that begins with < and ends with >. Tags come in three flavors:

    start-tag, such as <section>;
    end-tag, such as </section>;
    empty-element tag, such as <line-break />.

So I'm looking to rename all of the above tags of one name to another. As foo to bar or bar to baz, etc.

running saxonb-xslt returns:

Saxon 9.1.0.8J from Saxonica

Perhaps this version of Saxon doesn't have capabilities, or, more likely, the xslt is flawed.

truncated xml from a larger file:

<csv>
  <foo>
    <entry>Reported_Date</entry>
    <entry>HA</entry>
    <entry>Sex</entry>
    <entry>Age_Group</entry>
    <entry>Classification_Reported</entry>
  </foo>
  <bar>
    <entry>2020-01-26</entry>
    <entry>Vancouver Coastal</entry>
    <entry>M</entry>
    <entry>40-49</entry>
    <entry>Lab-diagnosed</entry>
  </bar>
  <record>
    <baz>2020-02-02</baz>
    <entry>Vancouver Coastal</entry>
    <entry>baz</entry>
    <entry>50-59</entry>
    <entry>Lab-diagnosed</entry>
  </record>
  <record>
    <entry>2020-02-05</entry>
    <entry>Vancouver Coastal</entry>
    <entry>F</entry>
    <entry>20-29</entry>
    <entry>Lab-diagnosed</entry>
  </record>
</csv>

the xslt file:

<?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 indent="yes"/>

  <xsl:mode on-no-match="shallow-copy"/>
  <xsl:template match="foo">
    <baz><xsl:apply-templates/></baz>
  </xsl:template>
</xsl:stylesheet>

error:

Error at xsl:mode on line 9 column 41 of bc.rename.xslt:
  XTSE0010: Element xsl:mode must not appear directly within xsl:stylesheet
Error at xsl:mode on line 9 column 41 of bc.rename.xslt:
  XTSE0010: Unknown XSLT element: mode
Failed to compile stylesheet. 2 errors detected.

Both the xml document and the xslt document pass xmllint with no errors.

Upvotes: 0

Views: 1355

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 116992

xsl:mode requires XSLT 3.0. AFAIK, Saxon 9.1 only supports XSLT 2.0.

Try instead:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="foo">
    <baz>
        <xsl:apply-templates/>
    </baz>
</xsl:template>

</xsl:stylesheet>

Upvotes: 1

Related Questions