Groups | Blog | Home
all groups > dotnet xml > october 2003 >

dotnet xml : Replace <P> with nothing


alexandra.gerard NO[at]SPAM wunderman-i.com
10/20/2003 2:41:24 AM
Good morning all,

I have the following xml :
<?xml version="1.0" encoding="UTF-8"?>
<anchor>
<title>Seconde classe</title>
<content>
<P> Hello World, <b>here is a text in bold</b> and this is the rest
of the text</P>
<P> Hello World 2, this is the second paragraph ! <b>here is a text
in bold</b> and this is the rest of the text</P>
</content>
</anchor>

What I want is to remove the <P> and </P>

I try with the following xsl :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mydoctype[<!ENTITY nbsp "&#160;">]>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="html" encoding="ISO-8859-1"
omit-xml-declaration="yes" standalone="yes" indent="yes"/>

<xsl:template match="anchor">
<font class="copy"><b><xsl:value-of select="title" /></b></font><br/>
<xsl:apply-templates select="content"/>
</xsl:template>

<xsl:template match="content">
coucou
<xsl:if test="contains(., '&lt;P>')">
coucou2
<xsl:value-of select="substring-before(substring-after(., '&lt;P>'),
'&lt;/P>')"/>
</xsl:if>
</xsl:template>

</xsl:stylesheet>

but it doesn't work either.
Do you have an idea of how I should do it ?

Thanks in advance for your help,
Jake G.
10/21/2003 10:44:15 AM
Couldn't you just do a global find/replace within the XML document
itself? Seems simple enough.

- Jake G.

[quoted text, click to view]

Christoph Schittko [MVP]
10/21/2003 11:13:35 PM
You need an XSLT that copies all the content of <P> element. Try this:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="ISO-8859-1" omit-xml-declaration="yes"
standalone="yes" indent="yes"/>
<xsl:template match="anchor">
<font class="copy"><b><xsl:value-of select="title" /></b></font><br/>
<xsl:apply-templates select="content"/>
</xsl:template>
<xsl:template match="content">
kuckuck

<xsl:for-each select="P">
<xsl:apply-templates />

</xsl:for-each>

kuckuck2

</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>

--
HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor
[quoted text, click to view]

AddThis Social Bookmark Button