[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: request for help resolving ambiguous rule match

Subject: Re: request for help resolving ambiguous rule match
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 24 Nov 2008 11:12:04 -0500
Re:  request for help resolving ambiguous rule match
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
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@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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.