Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / XML / October 2003

Tip: Looking for answers? Try searching our database.

Replace <P> with nothing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Alexandra - 20 Oct 2003 10:41 GMT
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,
Alexandra
Jake G. - 21 Oct 2003 15:44 GMT
   Couldn't you just do a global find/replace within the XML document
itself? Seems simple enough.

- Jake G.

> Good morning all,
>
[quoted text clipped - 42 lines]
> Thanks in advance for your help,
> Alexandra
Christoph Schittko [MVP] - 22 Oct 2003 05:13 GMT
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>

Signature

HTH
Christoph Schittko [MVP]
Software Architect, .NET Mentor

>     Couldn't you just do a global find/replace within the XML document
> itself? Seems simple enough.
[quoted text clipped - 47 lines]
> > Thanks in advance for your help,
> > Alexandra

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.