![]() |
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 |
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> |
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/ |
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 06:04 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.