Re: [xsl] request for help resolving ambiguous rule match

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
At 2008-11-24 11:03 -0500, John A. Walsh wrote:
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

I hope this helps.

. . . . . . . . . . Ken

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:
Video course overview:
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.
Male Cancer Awareness Nov'07
Legal business disclaimers:

Current Thread