Re: [xsl] create escaped(?) html of some nodes

Subject: Re: [xsl] create escaped(?) html of some nodes
From: "Jan Limpens" <jan@xxxxxxxxxxx>
Date: Mon, 9 Oct 2006 23:45:21 -0300
Thanks guys,

got it to work now (forgot a namespace prefix I omitted in the
example). Seems I got quite a bit rusty with xslt, as I have not
worked with it for two years or so.

But there remains a problem with escaping. With converting a <Para> to
a <p> things were quite easy, but I have no Idea how I can transform

	<xsl:template match="entry:Image">
		<p class="ImageParagraph">
			<img src="{$application-path}{@href}" alt="{entry:Title}" />
			<br />
			<xsl:value-of select="entry:Description" />

and escape the html (make the brackets become %lt;) as well. Any ideas?

Thanks again,


Mukul, FYI: In the original project, I stored content in the above
mentioned notation, but this was over engineering. Now, for content
(everything inside <Body/>) editing I want to use a wysiwyg html
editor instead of hacking xml, while preserving the outside xml
structure. By escaping body's contents, I do not have to worry,
whether is is correct xhtml or not. As long as the browsers can render
it it, it is fine with me.

2006/10/9, Abel Braaksma <>:
Hi Jan,

Perhaps this is a way of doing so (not tested though):

<xsl:template match="Para">
    <xsl:value-of select="." />

If you do not want ALL Para elements to be interpreted like this, please
specify what you mean with "while leaving the others untouched".

Another way of doing the above is using CDATA. It may be better
readable, depending on your preference:
<xsl:template match="Para">
    <xsl:text><![CDATA[ <p> ]]></xsl:text>
    <xsl:value-of select="." />
    <xsl:text><![CDATA[ </p> ]]></xsl:text>

Please note: it is not guaranteed that the '>' character will be output
as '&gt;' in either scenario, as the serializer may decide to output it
as a literal '>'. This is, because only the &lt; and the &amp;
characters are the only characters _required_ to be output as entities
when their literal equivalent is needed, in order to make valid XML. The
following are equivalent if you output as XML (hope the mailer leaves it

<example>&lt;p>some text&lt;/p></example>
<example>&lt;p&gt;some text&lt;/p&gt;</example>
<example>&#x3C;p&#x3E;some text&#x3C;/p&#x3E;</example>

As far as I know, you cannot (easily) control how exactly these are
output by your processor.

Abel Braaksma

Jan Limpens wrote: > Hi, > > I need help creating an encoded html string from some nodes of a > document, while leaving the others untouched > I have got a xml file as such: > > <?xml version="1.0" encoding="utf-8"?> > <Entry pubdate="2006-10-08T20:25:36.65625-03:00" id="test" > xmlns="http://com/entry";> > <navi:show-in-list>true</navi:show-in-list> > <navi:order>99</navi:order> > <Thumbnail src="xxx.gif" /> > <Version xml:lang="en"> > <Title>enTitle</Title> > <NavigationTitle>enNavTitle</NavigationTitle> > <Body> > <Para>Hello Dolly!</Para> > </Body> > </Version> > <Version xml:lang="de"> > <Title>2deTitle</Title> > <NavigationTitle>2deNavTitle</NavigationTitle> > <Body> > <Para>Hallo Doris!</Para> > </Body> > </Version> > <Slideshow> > <Image src="sss.gif"> > <ImageInfo xml:lang="en"> > <Title>Title</Title> > <Description>Description</Description> > </ImageInfo> > </Image> > <Image src="2222.gif"> > <ImageInfo xml:lang="en"> > <Title>Title</Title> > </ImageInfo> > </Image> > </Slideshow> > </Entry> > > and transform it to > > <?xml version="1.0" encoding="utf-8"?> > <Entry xmlns:navi="http//" > pubdate="2006-10-08T20:25:36.65625-03:00" id="test" > xmlns="";> > <navi:show-in-list>true</navi:show-in-list> > <navi:order>99</navi:order> > <Thumbnail src="xxx.gif" /> > <Version xml:lang="en"> > <Title>enTitle</Title> > <NavigationTitle>enNavTitle</NavigationTitle> > <Body>&lt;p&gt;Hello Dolly!&lt;/p&gt;</Body> > </Version> > <Version xml:lang="de"> > <Title>2deTitle</Title> > <NavigationTitle>2deNavTitle</NavigationTitle> > <Body>&lt;p&gt;Hallo Doris!&lt;/p&gt;</Body> > </Version> > <Slideshow> > <Image src="sss.gif"> > <ImageInfo xml:lang="en"> > <Title>Title</Title> > <Description>Description</Description> > </ImageInfo> > </Image> > <Image src="2222.gif"> > <ImageInfo xml:lang="en"> > <Title>Title</Title> > </ImageInfo> > </Image> > </Slideshow> > </Entry> > > How can I do this? I am using the .net 2.0 xslt implementation. Big > thanks in advance,


Current Thread