• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

priority of templates.

 
Vasim Patel
Ranch Hand
Posts: 87
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I came across a question in http://www.perfectxml.com/Quiz/XSLTQuiz.ASP
It says:

"Templates whose pattern matches a class of nodes, such as * or text() are assigned a default priority of ____
THe answer is: "-0.50."

I did not understand what the question meant. Can anyone please help me understand the meaning of priority of templates and what does the value
-0.50 mean?
 
Hari Vignesh Padmanaban
Ranch Hand
Posts: 578
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Vasim,

Quoted from W3c..Hope it helps

Link: http://www.w3.org/TR/xslt#dt-default-priority

----------------------------------------------------------------------
The priority of a template rule is specified by the priority attribute on the template rule. The value of this must be a real number (positive or negative), matching the production Number with an optional leading minus sign (-). The default priority is computed as follows:

If the pattern contains multiple alternatives separated by |, then it is treated equivalently to a set of template rules, one for each alternative.

If the pattern has the form of a QName preceded by a ChildOrAttributeAxisSpecifier or has the form processing-instruction(Literal) preceded by a ChildOrAttributeAxisSpecifier, then the priority is 0.

If the pattern has the form NCName:* preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.25.

Otherwise, if the pattern consists of just a NodeTest preceded by a ChildOrAttributeAxisSpecifier, then the priority is -0.5.

Otherwise, the priority is 0.5.

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.

--------------------------------------------------------------------

I guess that explains why teh value was -0.5 as * or text() are NOT SPECIFC TESTS

HTH
[ July 28, 2005: Message edited by: Hari Vignesh Padmanaban ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic