By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,445 Members | 3,172 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,445 IT Pros & Developers. It's quick & easy.

remove XHTML from XML source file

P: n/a
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:output 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

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a

Just add

<xsl:template match="xhtml:*" xmlns:xhtml="http://www.w3.org/1999/xhtml"/>

to your stylesheet if you want all xhtml elements and their content to
go, or

<xsl:template match="xhtml:*"
xmlns:xhtml="http://www.w3.org/1999/xhtml">
<xsl:apply-templates/>
</xsl:template>

If you want the content of xhtml elements to be processed.
David
Jul 20 '05 #2

P: n/a
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

Jul 20 '05 #3

P: n/a
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.

Jul 20 '05 #4

P: n/a
"Fr*********@gmail.com" <Fr*********@gmail.com> writes:
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
Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.