[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Priority issue with select="node()"

Subject: Priority issue with select="node()"
From: "Andrew Campbell andrew.campbell@xxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 21 Jul 2016 14:44:19 -0000
 Priority issue with select="node()"
Hi,

I have an xml file where I want to filter out all instances of a particular
element *except* those with specific attributes. I have got some XSLT that
does this.

Here is an example of the XML that needs filtered:

<resource>
    <method href="ref1"/>
    <method href="ref2"/>
    <method href="ref3"/>
 </resource>

And here is the XSLT that I am using:

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

    <xsl:template match="node()">
       <xsl:call-template name="identity"/>
   </xsl:template>

    <xsl:template
            match="
                  /
                 | @*
                 | method[@href = 'ref1']
                 ">
        <xsl:call-template name="identity"/>
    </xsl:template>

    <xsl:template match="method"/>

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

</xsl:stylesheet>

When I use Saxon on the command line to transform the XML, I get this output:

<?xml version="1.0" encoding="UTF-8"?><resource>
    <method href="ref1"/>


 </resource>

Which is exactly what I want.

The first two templates are identical in terms of content, but if I try to
combine them into one template by combining their match attributes like this:

match="
                  /
                 | @*
                 | method[@href = 'ref1']
                 | node()
                 "

I get the following output

<?xml version="1.0" encoding="UTF-8"?><resource>
    <method href="ref1"/>
    <method href="ref2"/>
    <method href="ref3"/>
 </resource>

It looks like a priority issue b for some reason the node() match is higher
priority than the <xsl:template match="method"/> when it is included in the
other template, but not when it is in its own template.

I canbt see why this is happening. Section 6.4 of the spec
<https://www.w3.org/TR/xslt20/#conflict> says bIf the pattern contains
multiple alternatives separated by | , then the template rule is treated
equivalently to a set of template rules, one for each alternative.b This
implies to me that the priority shouldnbt change just because node() is now
included alongside the other alternatives in a single match attribute.

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.