Subject: Re: [xsl] Ignoring ambiguous matches From: Ihe Onwuka <ihe.onwuka@xxxxxxxxx> Date: Thu, 13 Feb 2014 01:40:59 +0000 |
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@xxxxxxxxx> 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Ignoring ambiguous matche, Graydon | Thread | Re: [xsl] Ignoring ambiguous matche, Ihe Onwuka |
Re: [xsl] Ignoring ambiguous matche, Graydon | Date | Re: [xsl] Ignoring ambiguous matche, Ihe Onwuka |
Month |