Subject: Re: [xsl] request for help resolving ambiguous rule match From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Mon, 24 Nov 2008 11:12:04 -0500 |
In my xml (TEI P5 documents), I have structures like this: ... The above represents a stanza <lg> with lines of verse <l> that contain quotes <q> that extend over the hierarchy of the lines. I want to match the <q> children (with both @next and @prev) of the first line <l> of a stanza <lg>.
Something like this works: <xsl:template match="lg/l[position() = 1]/ q[@next and @prev]"/>
But I also have (and need) a template that simply matches "q[@next and @prev]", so my processor (Saxon9b) is throwing a warning about an ambiguous rule match, with ambiguity between "lg/l[position() = 1]/ q[@next and @prev]" and "q[@next and @prev]".
So my question Can someone please help me out with another way to express "lg/l[position() = 1]/q[@next and @prev]" that will resolve the ambiguity?
Only the stylesheet writer knows for sure which way to resolve any ambiguity, and then they convey that in their stylesheet using priority.
You have an ambiguity, and it sounds like both conditions need to be there, but the question is, do you want only one or both to "fire" when the node is sent to your stylesheet?
On the one you want to fire first or only, add priority="1" to the template rule.
If you want both to fire, then add the priority as above and inside that first template rule, instead of using <xsl:apply-templates/>, in XSLT 2.0 use <xsl:next-match/> and then the processor will review all matching templates *except* the one that just matched and will invoke the second one.
So, as you can see, it is up to the stylesheet write to distinguish the template rules by using the priority attribute.
Many stylesheets don't use priority because the shape of the match pattern governs a default value for priority, where anything more complex than a simple name has the same priority value of ".5" (after all, the processor can't decide for you which of two different patterns more complex than a simple name has higher priority than the other). There are other implicit layers of priority described in the specification and in training materials. In many simple stylesheets the implicit priority suffices.
-- Upcoming XSLT/XSL-FO, UBL and code list hands-on training classes: : Sydney, AU 2009-01/02; Brussels, BE 2009-03; Prague, CZ 2009-03 Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video Video sample lesson: http://www.youtube.com/watch?v=PrNjJCh7Ppg Video course overview: http://www.youtube.com/watch?v=VTiodiij6gE G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Male Cancer Awareness Nov'07 http://www.CraneSoftwrights.com/s/bc Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] request for help resolving am, John A. Walsh | Thread | Re: [xsl] request for help resolvin, Andrew Welch |
[xsl] request for help resolving am, John A. Walsh | Date | Re: [xsl] request for help resolvin, Andrew Welch |
Month |