ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> xsl-list
xsl-list
RE: [xsl] How to add a top level element to the result ?
by Samuel Abraham other posts by this author
Dec 20 2001 9:37AM messages near this date
Re: [xsl] XPath Question. | Re: [xsl] How to add a top level element to the result ?
hi,
Interesting.....It worked.

In the apply templates below
  <xsl:template match="/"> 
<Message> <xsl:apply-templates /></Message>
</xsl:template> 

If I change the expression for match to /A/B//C instead of / ie,similar to the match express
ion in the next rule then
it wont work.
Why is it so?
A/B//C means match C or all its descendants and then apply the templates.
So what is preventing the tag from being displayed?
 thanks
  Samuel Abraham



---------------------------------------- Message History -----------------------------------
-----


From: chris@bayes.co.uk@[...].com on 12/20/2001 08:58 AM GMT

Please respond to xsl-list@[...].com

DELEGATED - Sent by:     owner-xsl-list@[...].com


To:   xsl-list@[...].com
cc:
Subject:  RE: [xsl] How to add a top level element to the result ?


What about
<?xml version="1.0"?> 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
<Message> <xsl:apply-templates /></Message>
</xsl:template> 
<xsl:template match="/A/B//C"> 
<xsl:element name="{@attr1}"> 
<xsl:apply-templates /> 
<xsl:value-of select="@attr2"/> 
</xsl:element> 
</xsl:template> 
<xsl:template match="T"/> 
</xsl:stylesheet> 

Ciao Chris

XML/XSL Portal
http://www.bayes.co.uk/xml


>  -----Original Message-----
>  From: owner-xsl-list@[...].com
>  [mailto:owner-xsl-list@[...].com] On Behalf Of
>  Samuel Abraham
>  Sent: 20 December 2001 08:31
>  To: xsl-list@[...].com
>  Subject: [xsl] How to add a top level element to the result ?
> 
> 
> 
>  Hi all,
>  I have a xml file
>  <A>
>    <B>
>      <C attr1="c" attr2="12" />
>      <C attr1="d" >
>          <C attr1="f" attr2="15"/>
>      </C>
>      <C attr1="e" attr2="14" />
>      <T attr1="t"  attr2="16" />
>     </B>
>  </A>
> 
>   and applied 2 rules
> 
>    <xsl:template match="/A/B//C">
>      <xsl:element name="{@attr1}">
>         <xsl:apply-templates />
>               <xsl:value-of select="@attr2"/>
>             </xsl:element>
>    </xsl:template>
>    <xsl:template match="T"/>
> 
>  I need to add a top level element  to the result.
> 
>  eg:To add Message as a top level element.
> 
>  <Message>
>     <c>12</c>
>      <d>
>          <f>15</f>
>      </d>
>      <e>14</e>
>  </Message>
> 
>  Is it possible to do this?
> 
>   thanks
>    Samuel Abraham
> 
> 
> 
>  --
> 
>  This e-mail may contain confidential and/or privileged
>  information. If you are not the intended recipient (or have
>  received this e-mail in error) please notify the sender
>  immediately and destroy this e-mail. Any unauthorized
>  copying, disclosure or distribution of the material in this
>  e-mail is strictly forbidden.
> 
> 
> 
>   XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> 
> 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list




--

This e-mail may contain confidential and/or privileged information. If you are not the inten
ded recipient (or have received this e-mail in error) please notify the sender immediately a
nd destroy this e-mail. Any unauthorized copying, disclosure or distribution of the material
 in this e-mail is strictly forbidden.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
Thread:
Samuel Abraham
David Carlisle
Wendell Piez
David Carlisle
Chris Bayes

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved