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

RE: Result tree fragment to string? result as CDATA

Subject: RE: Result tree fragment to string? result as CDATA
From: "Rushforth, Peter" <prushfor@xxxxxxxxxxx>
Date: Thu, 28 Aug 2008 11:27:35 -0400
RE:  Result tree fragment to string?  result as CDATA
Hi,

I think I have a similar problem, but not constrained by the XSLT
version
or environment as for James.

Specifically,  I'm trying to generate an output document with a
description
element that looks like this

... other markup in result document...
<description><![CDATA[
              <html>
                <head>
                  <title>this is a test</title>
                </head>
                <body>
                  <b>this is a test</b>
                </body>
              </html>]]>
</description>
... more result document here ...

The solutions I've seen thus far all seem to end up with the markup
escaped.

I specifically don't want the markup to be escaped, but I do want
the <description> element to have an xs:string value.  Is there any way
to
achieve this?

Cheers,
Peter

> > > Do I have any options left for converting the result tree
> fragment
> > > to
> > a
> > > string?
> >
> > no
>
> Hmm... could he do something like:
>
> <xsl:variable name="xml">
>   <xsl:call-template name="serialize-tree">
>     <xsl:with-param name="nodes" select="$result-tree" />
>   </xsl:call-template>
> </xsl:variable>
>
> <xsl:template name="serialize-tree">
>   <xsl:param name="nodes" />
>   <xsl:apply-templates select="$nodes" mode="serialize" />
> </xsl:template>
>
> <xsl:template name="quote-attribute">
>   <xsl:param name="value" />
>   <!-- quote attribute's value -->
> </xsl:template>
>
> <xsl:template match="node()" mode="serialize" />
>
> <xsl:template match="@*" mode="serialize">
>   <xsl:variable name="dq">
>     <xsl:text>"</xsl:text>
>   </xsl:variable>
>   <xsl:variable name="value">
>     <xsl:call-template name="quote-attribute">
>       <xsl:with-param name="value" select="." />
>     </xsl:call-template>
>   </xsl:variable>
>   <xsl:value-of
> select="concat('&#32;',local-name(),'=',$dq,$value,$dq)" />
> </xsl:template>
>
> <xsl:template match="*" mode="serialize">
>   <xsl:value-of select="concat('&lt;',local-name())" />
>   <xsl:apply-templates select="@*" mode="serialize" />
>   <xsl:value-of select="string('&gt;')" />
>   <xsl:apply-templates select="*" mode="serialize" />
>   <xsl:value-of select="concat('&lt;/',local-name(),'&gt;')"
/> </xsl:template>
>
> The above doesn't handle namespaces, processing-instructions,
> comments, or mixed content, but it could be hacked to do so.
> Is there a reason why this approach would not work in XSL 1.0
> to satisfy his needs?

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-2007 All Rights Reserved.