471,066 Members | 1,287 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,066 software developers and data experts.

remove XHTML from XML source file

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
4 1754

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
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
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
"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.

Similar topics

13 posts views Thread by Tjerk Wolterink | last post: by
21 posts views Thread by Zenobia | last post: by
23 posts views Thread by Gustaf | last post: by
5 posts views Thread by markbfernandez | last post: by
21 posts views Thread by Russell Hoover | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.