[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Copy element with attributes

Subject: Re: Copy element with attributes
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Tue, 29 Nov 2005 13:56:17 +0000
xslt append text
> I have an xhtml file that I want to transform using
> xslt, like the one below. I want to prepend and append
> some text and change some body tag attributes but
> copy any other attributes. I cannot seem to get that
> done in the same transformation.
>
> An example:
>
> <html>
> <head>
> </head>
> <body text="#003366" bgcolor="#663300" onload="otherAttribs()">
> <p>My page</p>
> </body>
> </html>
>
> The result should be:
>
> <html>
> <head>
> </head>
> <body text="#000000" bgcolor="#ffffff" onload="otherAttribs()">
> Prepend text
> <p>My page</p>
> Append text
> </body>
> </html>

You want to use the identity transform with a special templates for
the <body> attributes and <p>:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="@*|node()">
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
</xsl:template>

<xsl:template match="body/@text">
	<xsl:attribute name="text">#000000</xsl:attribute>
</xsl:template>

<xsl:template match="body/@bgcolor">
	<xsl:attribute name="text">#ffffff</xsl:attribute>
</xsl:template>

<xsl:template match="p">
	<xsl:text>Prepend Text</xsl:text>
	<xsl:copy>
		<xsl:apply-templates select="@*|node()"/>
	</xsl:copy>
	<xsl:text>Append Text</xsl:text>
</xsl:template>

</xsl:stylesheet>


cheers
andrew

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.