This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Copying
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "Jose Aliste P." <jaliste at dim dot uchile dot cl>
- Cc: xsl-list at lists dot mulberrytech dot com
- Date: Thu, 29 Nov 2001 17:32:33 +0000
- Subject: Re: [xsl] Copying
- Organization: Jeni Tennison Consulting Ltd
- References: <Pine.OSF.3.95.1011129123133.2951C-100000@dim.uchile.cl>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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