473,738 Members | 9,555 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

template match, wich one should it be:

I have xml inpput like this:

<meta:empty/>
And xsl like this:
<xsl:template match="meta:emp ty">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?

Dec 8 '05 #1
8 1375
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>

Dec 8 '05 #2
ph************@ gmail.com 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?
Dec 8 '05 #3
>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

Dec 8 '05 #4
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.
Dec 8 '05 #5
ph************@ gmail.com 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...
Dec 8 '05 #6
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.

Dec 8 '05 #7
In article <dn*********@ne tlx020.civ.utwe nte.nl>,
Tjerk Wolterink <tj***@wolterin kwebdesign.com> wrote:
<xsl:templat e match="meta:emp ty">A</xsl:template>
<xsl:templat e 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 ChildOrAttribut eAxisSpecifier.

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 ChildOrAttribut eAxisSpecifier, because
// is not a ChildOrAttribut eAxisSpecifier.

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
Dec 8 '05 #8

Richard Tobin wrote:
In article <dn*********@ne tlx020.civ.utwe nte.nl>,
Tjerk Wolterink <tj***@wolterin kwebdesign.com> wrote:
<xsl:templat e match="meta:emp ty">A</xsl:template>
<xsl:templat e 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 ChildOrAttribut eAxisSpecifier.

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 ChildOrAttribut eAxisSpecifier, because
// is not a ChildOrAttribut eAxisSpecifier.

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:-)

Dec 8 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1762
by: brice | last post by:
Hello, I am using using the following code to transform a memo xml file. I am using Internet Explorer 6.0 to transform and view the file as HTML. <!-- ***** BEGIN XML ***** --> <?xml version="1.0"?> <?xml-stylesheet type="text/xsl" href="test.xsl"?> <MEMO ID="1"> <AUTHOR ID="1">
0
1173
by: Marc Schellens | last post by:
I have: template<class Sp> class Data_: public Sp { public: typedef typename Sp::Ty Ty; typedef Sp Traits; private:
7
3380
by: tthunder | last post by:
Hi @all, I have a trivial question, but I cannot find any answer :( <xsl:template match="note"> <b>Note:</b> </xsl:template> <xsl:template match="note"> <p><!-- CALL <xsl:template match="note"FROM HERE --></p> </xsl:template>
1
3451
by: Joe Strout | last post by:
Wow, this was harder than I thought (at least for a rusty Pythoneer like myself). Here's my stab at an implementation. Remember, the goal is to add a "match" method to Template which works like Template.substitute, but in reverse: given a string, if that string matches the template, then it should return a dictionary mapping each template field to the corresponding value in the given string. Oh, and as one extra feature, I want to...
0
8969
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8210
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4570
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2745
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.