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

Re: Copying

Subject: Re: Copying
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 29 Nov 2001 17:32:33 +0000
diable output escaping
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">
  &lt;<xsl:value-of select="name()" />>
    <xsl:apply-templates mode="serialize" />
  &lt;/<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">&lt;![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


Current Thread
  • Copying
    • Jose Aliste P. - Thu, 29 Nov 2001 10:43:00 -0500 (EST)
      • Jeni Tennison - Thu, 29 Nov 2001 12:31:39 -0500 (EST) <=

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.