XSLT: preserving an element with all its attributes

M

Martin Plantec

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
 
M

Martin Plantec

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>
 
M

Martin Plantec

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">
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top