xsl-list
[Top] [All Lists]

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

2008-11-24 11:12:29
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[(_at_)next and @prev]"/>

But I also have (and need) a template that simply matches "q[(_at_)next and
@prev]", so my processor (Saxon9b) is throwing a warning about an
ambiguous rule match, with ambiguity between "lg/l[position() = 1]/ q[(_at_)next and @prev]" and "q[(_at_)next and @prev]".

So my question ? Can someone please help me out with another way to
express "lg/l[position() = 1]/q[(_at_)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.

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:    http://www.youtube.com/watch?v=PrNjJCh7Ppg
Video course overview:  http://www.youtube.com/watch?v=VTiodiij6gE
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>