Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > template match, wich one should it be:

Reply
Thread Tools

template match, wich one should it be:

 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      12-08-2005
I have xml inpput like this:

<meta:empty/>


And xsl like this:


<xsl:template match="meta:empty">A</xsl:template>
<xsl:template match="//meta:*">B</xsl:template>


The namespaces meta or both bound to the same uri, so no
problem with that.

My Question,
what should be outputted when i input the meta:empty element,
A
or
B

My xsl processor outputs B, but i expect it to output A
because the match pattern "meta:empty" is more specifc then
"//meta:*"

What should it do?

 
Reply With Quote
 
 
 
 
phil.a.jenkins@gmail.com
Guest
Posts: n/a
 
      12-08-2005
I would have expected A to have a higher default priority than B, but
you could try forcing B's priority to a low value to make sure the
first template is being picked up.

i.e.

<xsl:template match="//meta:*" priority="-1">B</xsl:template>

 
Reply With Quote
 
 
 
 
Tjerk Wolterink
Guest
Posts: n/a
 
      12-08-2005
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> I would have expected A to have a higher default priority than B, but
> you could try forcing B's priority to a low value to make sure the
> first template is being picked up.
>
> i.e.
>
> <xsl:template match="//meta:*" priority="-1">B</xsl:template>
>


But what does the W3C say? Wich one should have priority?
 
Reply With Quote
 
Phil Jenkins
Guest
Posts: n/a
 
      12-08-2005
>From http://www.w3.org/TR/xslt#conflict

5.5 Conflict Resolution for Template Rules

....

Thus, the most common kind of pattern (a pattern that tests for a node
with a particular type and a particular expanded-name) has priority 0.
The next less specific kind of pattern (a pattern that tests for a node
with a particular type and an expanded-name with a particular namespace
URI) has priority -0.25. Patterns less specific than this (patterns
that just tests for nodes with particular types) have priority -0.5.
Patterns more specific than the most common kind of pattern have
priority 0.5.

.....

So bascially the more specific the match - the higher the default
priority should be

 
Reply With Quote
 
Tjerk Wolterink
Guest
Posts: n/a
 
      12-08-2005
Phil Jenkins wrote:
>>From http://www.w3.org/TR/xslt#conflict

>
> 5.5 Conflict Resolution for Template Rules
>
> ...
>
> Thus, the most common kind of pattern (a pattern that tests for a node
> with a particular type and a particular expanded-name) has priority 0.
> The next less specific kind of pattern (a pattern that tests for a node
> with a particular type and an expanded-name with a particular namespace
> URI) has priority -0.25. Patterns less specific than this (patterns
> that just tests for nodes with particular types) have priority -0.5.
> Patterns more specific than the most common kind of pattern have
> priority 0.5.
>
> ....
>
> So bascially the more specific the match - the higher the default
> priority should be
>


So my xsl processor is doing it wrongly?

i'm using Xalan.
 
Reply With Quote
 
Tjerk Wolterink
Guest
Posts: n/a
 
      12-08-2005
(E-Mail Removed) wrote:
> I would have expected A to have a higher default priority than B, but
> you could try forcing B's priority to a low value to make sure the
> first template is being picked up.
>
> i.e.
>
> <xsl:template match="//meta:*" priority="-1">B</xsl:template>
>


It works with this fix, thanks.

But i want to understand why it did'nt work...
 
Reply With Quote
 
Phil Jenkins
Guest
Posts: n/a
 
      12-08-2005
I'm curious too

Try swapping the two original (unfixed) templates around. If A now
occurs instead of B it means that they both have the same priority;
Xalan will pick the template that occurs last if more than one template
has the same priority when matched - if that makes sense!

My experience has always been to explicitly define the priority of any
items that I want to be considered last - i'm relatively new to the
default priority calculations, seems like extra complication having to
rely on the processor to decide.

 
Reply With Quote
 
Richard Tobin
Guest
Posts: n/a
 
      12-08-2005
In article <dn9g3g$s0$(E-Mail Removed)>,
Tjerk Wolterink <(E-Mail Removed)> wrote:

><xsl:template match="meta:empty">A</xsl:template>
><xsl:template match="//meta:*">B</xsl:template>


See http://www.w3.org/TR/xslt#conflict

The first pattern has priority 0 because it has the form QName
preceded by a ChildOrAttributeAxisSpecifier.

The second pattern has priority 0.5 because it doesn't fall into any
of the other listed categories. In particular, it isn't of the
form NCName:* preceded by a ChildOrAttributeAxisSpecifier, because
// is not a ChildOrAttributeAxisSpecifier.

So the second rules has higher priority.

The fact that //meta:* matches the same nodes as meta:*, which would
have priority -0.25, is not relevant

-- Richard
 
Reply With Quote
 
Phil Jenkins
Guest
Posts: n/a
 
      12-08-2005

Richard Tobin wrote:

> In article <dn9g3g$s0$(E-Mail Removed)>,
> Tjerk Wolterink <(E-Mail Removed)> wrote:
>
> ><xsl:template match="meta:empty">A</xsl:template>
> ><xsl:template match="//meta:*">B</xsl:template>

>
> See http://www.w3.org/TR/xslt#conflict
>
> The first pattern has priority 0 because it has the form QName
> preceded by a ChildOrAttributeAxisSpecifier.
>
> The second pattern has priority 0.5 because it doesn't fall into any
> of the other listed categories. In particular, it isn't of the
> form NCName:* preceded by a ChildOrAttributeAxisSpecifier, because
> // is not a ChildOrAttributeAxisSpecifier.
>
> So the second rules has higher priority.
>
> The fact that //meta:* matches the same nodes as meta:*, which would
> have priority -0.25, is not relevant
>
> -- Richard


Superb answer - the W3C terminology was predictably obtuse so
appreciate the translation

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MCSD vs. MCPD: wich path? Ca r l o s A n t o n i o MCSD 1 03-07-2006 03:53 AM
Wich 28xx Router? Christoph Gartmann Cisco 1 09-29-2005 06:38 PM
Wich control fired the postback action Fabiano ASP .Net 1 06-20-2005 08:55 PM
XPATH: Selecting child nodes wich are NOT equal to Tjerk Wolterink XML 9 02-07-2005 08:47 PM
Identify wich button was pressed! bredal Jensen ASP .Net 5 07-16-2004 08:31 AM



Advertisments