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

Re: macthed element lost structures?

Subject: Re: macthed element lost structures?
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Sat, 27 Mar 2004 23:28:16 +0100
firststream
lech wrote:
> my xsl lost all marks of matched elements
> I want the output to be    <FirstStream><name>     TheFirstName    </name>
> <data>  TheFirstData   </data> /FirstStream>....
> 
> But the output I got is:    <FirstStream>    TheFirstName    TheFirstData
> </FirstStream>....
> 
> the" <name>" and "<data>"is lost,  does anybody have some idea why?

You probaly run into default templates. The problem is here:

> <xsl:template match="overall">
> <FirstStream><xsl:apply-templates select="stream1"/>
               ^^^^^^^^^^^^^^^^^^^^^^^^^
You tell the processor to recursively apply templates.
The processor looks for matching templates, and if there
aren't any, it falls back to the default template, which
simply applies templates to child nodes. It ultimately
copies text nodes, but wont copy elements or attributes.

If you want to have a literal copy of the subtree, use
xsl:copy-of instead of xsl:apply-templates:

 <xsl:template match="overall">
   <FirstStream>
     <xsl:copy-of select="stream1"/>
   </FirstStream>
   <SecondStream>
     <xsl:copy-of select="stream2|stream3"/>
   <SecondStream>
 </xsl:template>
This is also very fast.

If you have some other templates you want kick in on elements
deeper down the tree, add a generic copy-through template to
your style sheet:
 <xsl:template match="node()|@*">
    <xsl:copy>
       <xsl:apply-template select="node()|@*"/>
    </xsl:copy>
 </xsl:template>
This template matches everything and will therefore be used
rather than falling back to the default templates.

See
 http://www.w3.org/TR/xslt#built-in-rule
and
 http://www.w3.org/TR/xslt#copying
for more details.

J.Pietschmann

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-2013 All Rights Reserved.