Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: preserving an element with all its attributes

Reply
Thread Tools

XSLT: preserving an element with all its attributes

 
 
Martin Plantec
Guest
Posts: n/a
 
      10-28-2005
This is a very simple question, from a beginner in XSLT.

Suppose my XML says

<para>The word <a href="there.html">link</a> goes there.</para>

What XSLT rule would preserve the a element with all attributes?

By now I have learned I can write:

<xsl:template match="a">
<a><xsl:apply-templates /></a>
</xsl:template>

but this looses the attribute. And including no special rule for the a
element will suppress it from output. And also: if I have a 10 elements
for which this is what I want to do, is there a shorthand to treat all
of them in this way (i.e. keeping everything as in source).

Thanks!

Martin

 
Reply With Quote
 
 
 
 
Martin Plantec
Guest
Posts: n/a
 
      10-28-2005
Hey! I just found the answer by reading another post in this group.
Thanks.

PS: here it is:

<xsl:template match="a">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      10-28-2005


Martin Plantec wrote:


> <para>The word <a href="there.html">link</a> goes there.</para>
>
> What XSLT rule would preserve the a element with all attributes?


The identity transformation is even mentioned in the XSLT 1.0 specification:
<http://www.w3.org/TR/xslt#copying>


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
Martin Plantec
Guest
Posts: n/a
 
      10-28-2005
Thanks a lot. And to answer my original question entirely, several
elements can be treated that way at once, by using:

<xsl:template match="a|element2|element3">

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 14 04-03-2010 10:08 AM
Its a bird, its a plane, its.. um, an Attribute based System? thunk Ruby 0 04-01-2010 10:25 PM
Its a bird, its a plane, no ummm, its a Ruide thunk Ruby 1 03-30-2010 11:10 AM
Sign preserving Vs value preserving sophia.agnes@gmail.com C Programming 4 12-07-2007 03:14 PM
integral promotion, arithmetic conversion, value preserving, unsigned preserving??? TTroy C Programming 16 01-31-2005 10:20 PM



Advertisments