Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   XML (http://www.velocityreviews.com/forums/f32-xml.html)
-   -   XSLT: preserving an element with all its attributes (http://www.velocityreviews.com/forums/t170094-xslt-preserving-an-element-with-all-its-attributes.html)

Martin Plantec 10-28-2005 03:03 PM

XSLT: preserving an element with all its attributes
 
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


Martin Plantec 10-28-2005 03:10 PM

Re: XSLT: preserving an element with all its attributes
 
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>


Martin Honnen 10-28-2005 03:21 PM

Re: XSLT: preserving an element with all its attributes
 


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/

Martin Plantec 10-28-2005 03:35 PM

Re: XSLT: preserving an element with all its attributes
 
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">



All times are GMT. The time now is 04:13 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.