[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: build-in template question

Subject: Re: build-in template question
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 04 Sep 2008 18:37:47 -0400
Re:  build-in template question
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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.