remove XHTML from XML source file

F

FrankIsHere

Hi!

I cannot figure out how to remove XHTML tags from an XML source file
using XSLT.
Here's what I have:
source XML file:

<?xml version='1.0'?>
<Offer ID="S0173" xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xhtml="http://www.w3.org/1999/xhtml" >
<GroupInfo>
<Abstract>
<br xmlns="http://www.w3.org/1999/xhtml" />
<i><br/></i><br/><p>test</p>
<br xmlns="http://www.w3.org/1999/xhtml" />
</Abstract>
<Name>Overview</Name>
</GroupInfo>
</Offer>

And this is transformed using this stylesheet:

<xsl:stylesheet
xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
version='1.0' >
<xsl:eek:utput method="html" encoding="utf-8" />
<xsl:template match="*|@*|text()">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

<xsl:template match="Abstract//p|Abstract//br">
<xsl:value-of
select="." />
</xsl:template>
</xsl:stylesheet>


This is the result of the transformation:

<Offer xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<GroupInfo>
<Abstract>
<br xmlns="http://www.w3.org/1999/xhtml"></br>
<i></i>test
<br xmlns="http://www.w3.org/1999/xhtml"></br>
</Abstract>
<Name>Overview</Name>
</GroupInfo>
</Offer>


What I want to get is eliminate all XHTML tags from the source XML
file. So for instance the <br
xmlns="http://www.w3.org/1999/xhtml"></br> should not be there. I
figured out how to remove the regular HTML but not when it's XHTML
format.

I appreciated any help!
Frank
 
F

FrankIsHere

Thank you David but I wanted to apply the removal only on one element,
the "abstract" element. How can I limit it to just one node?

Thanks!!
Frank
 
F

FrankIsHere

Thanks but I figured it out. I would put:

<xsl:template match="Abstract//xhtml:br"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:value-of
select="." />
</xsl:template>

to remove all XHTML tags from the Abstract Element.
 
D

David Carlisle

Thanks but I figured it out. I would put:

<xsl:template match="Abstract//xhtml:br"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:value-of
select="." />
</xsl:template>

to remove all XHTML tags from the Abstract Element.


well no, that would only remove br elements (you could use * as I had it
to remove them all) also you don't want the xsl:value-of a br presumably
has no content anyway so it is not doing anything.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top