xsl-list
[Top] [All Lists]

Re: [xsl] Ignoring ambiguous matches

2014-02-12 19:41:13
Give or take the priority setting it would look something like a
series of templates of the following ilk.

  <xsl:template match="@title" priority="99">
    <xsl:param name="title" select="."/>
    <xsl:next-match>
      <xsl:with-param name="title" select="replace($title, 'some regex','')"/>
    </xsl:next-match>
  </xsl:template>

The alternative is a humongous regex or the introduction of
intermediate variables ($title1, $title2 etc....) to allow you to
break the humongous regex down. This is what I started with and will
probably revert to as the next-match way introduces alot of
boiler-plate and I can't afford the distraction of figuring out
whether and how to abstract it away.




On Thu, Feb 13, 2014 at 1:35 AM, Graydon <graydon(_at_)marost(_dot_)ca> wrote:
On Thu, Feb 13, 2014 at 01:06:25AM +0000, Ihe Onwuka scripsit:
I am about to write several template rules that will all match the
same node but will each apply (or try to apply) a different edit.

I don't care the order in which these are applied as long as each gets
a shot at applying it's edit.

I was wondering whether I can just ignore the ambiguous match warnings
and be confident that everything is A - ok or whether I have to
diligently invent template priorities to prevent that.

If you need everything to match, it's not safe to ignore ambiguous rule
match warnings; you're going to get only one of the rules matching,
hopefully the last one.

For XSLT 2.0, last thing in section 6.4 of the spec:

"It is a recoverable dynamic error if the conflict resolution algorithm
for template rules leaves more than one matching template rule. The
optional recovery action is to select, from the matching template rules
that are left, the one that occurs last in declaration order."

Why not find the node and do everything you need to do to that node
inside that template.

Usually something like

<xsl:variable name="pass1">
    <xsl:apply-templates mode="pass1" select="."/>
</xsl:variable>

<xsl:variable name="pass2">
    <xsl:apply-templates mode="pass2" select="$pass1"/>
</xsl:variable>

and eventually

<xsl:sequence select="$passn"/>

Whatever transform you want at each step has to be present as templates
with the appropriate modes.

Next match for multiple templates is tricky, you have to be sure all the
templates have exactly the same priority or set the priorities carefully
and this, well, there's a reason one generally prefers to let the
processor deal with priority.

-- Graydon

--~------------------------------------------------------------------
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>
--~--


--~------------------------------------------------------------------
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>
--~--