xsl-list
[Top] [All Lists]

Re: [xsl] build-in template question

2008-09-05 05:08:42
G. Ken Holman wrote, On 2008-09-05 00:45:
At 2008-09-05 00:25 +0200, Jonas Mellin wrote:
Garvin Riensche wrote, On 2008-09-05 00:17:
Hello,

I have a question concerning text nodes. If I have an xml file like

<root>
  <e>text</e>
</root>

and a template like

<xsl:template match="e">
  <xsl:copy/>
</xsl:template>

than, the output will be "<e>text</e>".

Is the text insterted to the output by xsl:copy or by the build-in template

<xsl:template match="text()|@*">
  <xsl:value-of select="."/>
</xsl:template>
?
During evaluation of applicable templates on a particular node, the most specific template is chosen.

This is not precisely true.
I assume you refer to
http://www.w3.org/TR/xslt20/#conflict and
http://www.w3.org/TR/xslt#conflict, right?


If two or more templates is of the same level of specification, then the template with the highest priority is chosen.

Yes, this is true, but the impact on priority by specificity is *very* limited and not quite as you say.
I was referring too explicit priority set in the template specification, not the default priority as defined in the conflict resolution.

For example, the priority of all of the following templates are the same and all are in conflict for a document element named "x" that has both an attribute named "abc" and an attribute named "def":

  <xsl:template match="x[(_at_)abc]">

  <xsl:template match="x[(_at_)abc][@def]">

  <xsl:template match="/x">

I read the above three as having different specificity, yet they all have the same priority value of ".5".
Agree.
I based my answer on Eric T. Rays book "Learning XML" in which he states "It is possible for more than one rule to match a node. In this case, the XSLT processor must select exactly one rule from the mix, and that rule should meet our expectations for best match." This is followed by the precedence rules for XSLT 1.0 in text format. I sloppily rephrased this as the most specific template. Sorry for this.

I have forgotten what happens if two templates cannot be separated (a situaiton that I try to avoid), although a qualified guess is that an XSLT 1.0 processor does something and an XSLT 2.0 processor returns an error message.

Not sure what you are talking about here.

If you are trying to talk to the "union" operator (the vertical bar), this only tells the processor to treat the template severally across all of the unioned patterns as if each one were written out on its own with the identical template content.

Nope, I tried to address the problem that you gave an example of, that is, we have N matching templates and it is not possible to resolve the conflict without explicit priorities set in the templates. Further, I tried to address that it is only the design that XSLT 1.0 tries to do something even could be viewed as erroneous, whereas XSLT 2.0 attempts to generate error messages instead.

Anyway, in this case, the match="e" is more specifc than match="text()|@*" so the first template is chosen.

Just to set the archive record straight, the match for an element is not in conflict with the match for a text node or an attribute node, so the XSLT principles of priority= and template conflict resolution don't even come into play. The above quoted sentence is not true.
Agree. Sorry, I missed the '@' sign.

Wisdom: Never reply in public when you are too tired.

/Jonas

I hope this is considered helpful.

. . . . . . . . . . . Ken

--
Upcoming XSLT/XSL-FO hands-on courses:      Wellington, NZ 2009-01
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


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



--
Carpe Diem!
===
Jonas Mellin, Assistant Professor in Computer Science
School of Humanities and Informatics, Building E-2
University of Skövde, P.O. Box 408, SE-541 28 Skövde, Sweden
Phone: +46 500 448321, Fax: +46 500 448399
Email: jonas(_dot_)mellin(_at_)his(_dot_)se, URL: http://www.his.se/melj


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