Subject: RE: cdata-section-elements - not wrapping real xml in cdata markers
From: "Lars Huttar" <lars_huttar@xxxxxxx>
Date: Wed, 12 Nov 2003 16:36:22 -0600
|
Wendell Piez wrote:
> Sent: Monday, November 10, 2003 3:43 PM
> I think what you need is to write out the "elements" inside
> the string you
> want to preserve in escaped form. You can do this with
> templates easily
> enough. This means they won't look like elements in your
> stylesheet --
> because you don't want elements in your output. For example
> (here are a
> couple of templates I have lying around that will do this):
Thank you for these. They were just what I needed for something
I'm doing.
(Caveat to anyone who might use this: a greater-than sign
is missing in the "write-endtag" template as it appeared
in the email.)
> <xsl:template name="write-starttag">
> <xsl:text><</xsl:text>
> <xsl:value-of select="local-name()"/>
> <xsl:for-each select="@*">
> <xsl:call-template name="write-attribute"/>
> </xsl:for-each>
> <xsl:text>></xsl:text>
> </xsl:template>
>
> <xsl:template name="write-endtag">
> <xsl:text></</xsl:text>
> <xsl:value-of select="local-name()"/>
> <xsl:text></xsl:text>
A greater-than sign is missing here (lost in the mail?)
> </xsl:template>
>
> <xsl:template name="write-attribute">
> <xsl:text> </xsl:text>
> <xsl:value-of select="local-name()"/>
> <xsl:text>="</xsl:text>
> <xsl:value-of select="."/>
> <xsl:text>"</xsl:text>
> </xsl:template>
>
> <xsl:template match="*" mode="escape-xml">
> <xsl:call-template name="write-starttag"/>
> <xsl:apply-templates/>
Btw some will want to add mode="escape-xml" to the above
line for recursive escaping.
> <xsl:call-template name="write-endtag"/>
> </xsl:template>
>
> <xsl:template match="warning">
> <xsl:apply-templates mode="escape-xml"/>
> </xsl:template>
Lars
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|