[Top] [All Lists]

Re: [xsl] Help describing the behavior of a Path Expression

2019-06-04 17:07:30
There are three templates here, that match overlapping sets of nodes. None has 
an explicit priority, so each takes a default priority based on the form of the 
match pattern. The rules are here:


The rules indicate that the priority for "node()" is -0.5 (rule 10); the 
priority for "item" is 0 (rule 6), and the priority for "item[discount[...]]" 
is +0.5 (rule 11). Each <item> element selected by an xsl:apply-templates 
instruction is processed using the highest-priority rule that it matches.

In this example the default rules for priorities have the desired effect. This 
isn't always the case. In more complex cases, it's good practice to allocate 
explicit priorities using the "priority" attribute.

Michael Kay

On 4 Jun 2019, at 21:06, Bridger Dyson-Smith bdysonsmith(_at_)gmail(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

Hi all - 

apologies for the awkward title. I was helping a coworker with a problem, 
where we wanted to ignore certain elements that didn't meet certain 
requirements. We had a working template for the elements with requirements, 
but how to make the processor ignore the others? My suggestion was to write 
an empty template for the element (`item` below), with the paraphrased 
explanation: "the processor with ignore the general expression but match on 
the specific expression", but I'm clueless about the "why doesn't the 
processor ignore all of the `item` elements, then?". I have the sense that 
explanation might be approximately right, but it (and I) would benefit from 
an improved understanding of what's actually happening.

Would someone be willing to share some better words to describe this? Is it 
as easy as saying that since $expression-a (`item[discount]`) has a 
predicate, it has a higher precedence than $expression-b (`item`) (or maybe 
more simply: operator precedence - I see a note in Dr. Kay's XSLT/XPath 2.0 
book about this)?

Thanks in advance for your time and trouble.

Here's a contrived example of our source document:
<!-- source -->
  <item color="red" size="m">
  <item color="blue" size="m">
    <discount percentage="20"/>
  <item color="yellow" size="l">
    <discount percentage="10"/>

And a stylesheet:
<!-- xsl -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform 
  <xsl:output encoding="UTF-8" method="xml" indent="yes"/>
  <xsl:strip-space elements="*"/>
  <!-- identity transform -->
  <xsl:template match="@*|node()">
      <xsl:apply-templates select="@*|node()"/>
  <xsl:template match="item[discount[@percentage ge '15']]">
    <discount-item color="{@color}" size="{@size}" price="{price}" 
  <xsl:template match="item"/>
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/293509> (by 
email <>)
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
<Prev in Thread] Current Thread [Next in Thread>