Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] build-in template question

From: "G. Ken Holman" <gkholman@-------------------->
To:
Date: 9/4/2008 10:39:00 PM
At 2008-09-05 00:17 +0200, Garvin Riensche wrote:
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>".

I don't believe this is true ... you should be getting an empty 
element.  If you are getting text as well, then there is a problem 
with your XSLT processor.



To prove my first-blush response, I've coded an example below.



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

Neither.



Template matching only happens when triggered by 
<xsl:apply-templates/> either explicitly in the stylesheet or behind 
the scenes in the built-in template rule for elements and the root node.



In your example you are copying the element node but saying nothing 
the nodes attached to or below the element node.  Therefore, in the 
result tree, you only get the element node.  When this is serialized 
the element markup will be one of two syntaxes (you don't get control 
over which):  either an empty element tag or a start tag immediately 
followed by an end tag.



I hope this helps.



. . . . . . . . . Ken



t:\ftemp>type garvin.xml



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

t:\ftemp>type garvin.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

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

</xsl:stylesheet>
t:\ftemp>xslt garvin.xml garvin.xsl con
<?xml version="1.0" encoding="utf-8"?>
  <e/>

t:\ftemp>



--
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@xxxxxxxxxxxxxxxxxxxx
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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent