This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: remove extra chars from the entire xml document
- From: Mike Brown <mike at chilled dot skew dot org>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Wed, 26 Jun 2002 21:54:15 -0600 (MDT)
- Subject: Re: [xsl] remove extra chars from the entire xml document
- Reply-to: xsl-list at lists dot mulberrytech dot com
Arbee Shadkam wrote:
> thanks Roland for the reply, Bu my xml document is gigantic, so i can not
> have a translate function for each tag. I was wondering if there would be a
> better way like a template to apply to the entire document?
Do an identity transformation (recurse through document, copying every node),
and for text nodes, translate before copying. I assume by 'fields' you mean
text node children of element nodes. You could easily adapt it to do
attribute nodes as well.
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="no"/>
<xsl:variable name="deleteThese">&'*</xsl:variable>
<xsl:template match="/|*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="translate(.,$deleteThese,'')"/>
</xsl:template>
</xsl:stylesheet>
- Mike
____________________________________________________________________________
mike j. brown | xml/xslt: http://skew.org/xml/
denver/boulder, colorado, usa | resume: http://skew.org/~mike/resume/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list