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

Subject: Re: [xsl] Help describing the behavior of a Path Expression
From: "Bridger Dyson-Smith bdysonsmith@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 4 Jun 2019 20:24:31 -0000
Hi David

On Tue, Jun 4, 2019 at 4:16 PM David Carlisle d.p.carlisle@xxxxxxxxx <
xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:

> did you mean @percentage ge '15'] here?  that is string comparison,
> you want 15 if you want a numeric comparison
>
> Yes :) - sorry for the typos in the example.


> However to answer the question, the pattern "item" does have a lower
> default priority than the pattern "item[anything]"  (strictly speaking
> this is an xslt pattern not an xpath)
>
> Thanks for helping clear that up! I'll roll with that the next time this
topic comes around.

> David
>
> Best,
Bridger


>
> On Tue, 4 Jun 2019 at 21:06, Bridger Dyson-Smith bdysonsmith@xxxxxxxxx
> <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> 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.
> > Best,
> > Bridger
> >
> > Here's a contrived example of our source document:
> > <!-- source -->
> > <items>
> >   <item color="red" size="m">
> >     <price>15.00</price>
> >   </item>
> >   <item color="blue" size="m">
> >     <price>15.00</price>
> >     <discount percentage="20"/>
> >   </item>
> >   <item color="yellow" size="l">
> >     <price>15.00</price>
> >     <discount percentage="10"/>
> >   </item>
> > </items>
> >
> > And a stylesheet:
> > <!-- xsl -->
> > <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 encoding="UTF-8" method="xml" indent="yes"/>
> >   <xsl:strip-space elements="*"/>
> >
> >   <!-- identity transform -->
> >   <xsl:template match="@*|node()">
> >     <xsl:copy>
> >       <xsl:apply-templates select="@*|node()"/>
> >     </xsl:copy>
> >   </xsl:template>
> >
> >   <xsl:template match="item[discount[@percentage ge '15']]">
> >     <discount-item color="{@color}" size="{@size}" price="{price}"
> discount="{discount/@percentage}"/>
> >   </xsl:template>
> >
> >   <xsl:template match="item"/>
> > </xsl:stylesheet>
> > XSL-List info and archive
> > EasyUnsubscribe (by email)

Current Thread