|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Copying
Hi Jose,
> So, I want to serialize the content of the element to HTML and
> including in the result tree...
There are three ways that I know of for doing this. The purest way is
to write a set of templates that serializes the nodes, for example:
<xsl:template match="*" mode="serialize">
<<xsl:value-of select="name()" />>
<xsl:apply-templates mode="serialize" />
</<xsl:value-of select="name()" />>
</xsl:template>
(but expanded to add attributes and so on).
The second option is to use diable-output-escaping to wrap a CDATA
section around the XHTML that you want to serialize, as follows:
<xsl:template match="atag">
<xsl:text disable-output-escaping="yes"><![CDATA[</xsl:text>
<xsl:copy-of select="." />
<xsl:text disable-output-escaping="yes">]]></xsl:text>
</xsl:template>
(This might not work in all processors - disable-output-escaping is
usually something to avoid.)
Finally, you can create an extension function that does it for you. If
you're using MSXML, for example, then you can define a serialize
template in 'my' namespace with:
<msxsl:script implements-prefix="my" language="javascript">
<![CDATA[
function serialize(nodes) {
var XMLstring;
for (var i = 0; i < nodes.length; i++) {
XMLstring += nodes.item(i).xml;
}
return XMLstring;
}
]]>
</msxsl:script>
And then serialize the content of the atag element with:
<xsl:template match="atag">
<xsl:value-of select="my:serialize(node())" />
</xsl:template>
You can probably come up with similar extension functions for other
processors, depending on the APIs that they support.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








