Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stripping null characters from XML elements

Status
Not open for further replies.

Hexonx

Programmer
Jan 10, 2001
102
US
I'm transforming xml and want to strip out null characters in the elements.

The elements look like this:
<myEl>&#0;&#0;&#0;</myEl>

My XSL rules look like this:
<xsl:if test=&quot;string-length(/myEl) > 0&quot;>
<outEl><xsl:value-of select=&quot;/myEl&quot;/></outEl>
</xsl:if>

For the 'select=' attribute, I've tried:
- translate(/myEl, &#0, 'x')
- translate(/myEl, '&#0', 'x')
- translate(/myEl, '&#0;', 'x')
- translate(/myEl, '&#0', 'x')
- translate(/myEl, '&#0;', 'x')
- translate(string(/myEl), '&#0;', 'x')
- translate(string(/myEl), '&#0;', 'x')

I've also tried <xsl:strip-space> at the root, but no effect.

I'm translating null to 'x' for now so I know that I'm capturing the nulls correctly, but never get a match; my output always has <myEl> with nulls embedded in it. The output xml is otherwise well-formed. Anyone know what I'm doing wrong?
 
I solved the problem, which had nothing to do with the XPath queries. My XSL stylesheet is a Content file in a VS.NET project. I forgot that VS DOESN'T copy content files to the output folder. Thus, all of my stylesheet edits were never used!

This is what I ultimately used to remove the nulls:
translate(/myEl, '&#0', '')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top