Subject: Re: [xsl] How to Replace Special Characters ? From: Mike Brown <mike@xxxxxxxx> Date: Thu, 8 Aug 2002 10:50:34 -0600 (MDT) |
Rohitav Samanta wrote: > To get rid of the special characters I have written the following template. > > <xsl:call-template name="transformXMLString"> > <xsl:with-param name="StringToTransform"> > <xsl:value-of select="//WorkHistory/xml/rs:data/z:row@Responsibilities" disable-output-escaping="yes"/> > </xsl:with-param> > </xsl:call-template> 1. disable-output-escaping has no effect here. It only affects serialization of text nodes in the result tree. You aren't serializing anything (not producing output). 2. You can also remove the value-of and put the select in the with-param. 3. When you select multiple nodes, value-of only looks at the first one, so you should try not to select more than the one you need. 4. '//' is rarely necessary unless you really need every WorkHistory element and you have no idea where those elements could be, relative to either the root node or where you are now. > <xsl:when test="contains($StringToTransform,'&#8220;')"> > <xsl:value-of select="translate($StringToTransform,'&#8220;','"')" /> > </xsl:when> 5. What you are testing for is the string '“' (7 characters) but your XML has been parsed.. those 7 characters no longer exist in the data. It is now one character: Unicode character number 8220. 6. You do not need a recursive template at all. The solution is simply to use translate() once: (replace $foo with the actual string to act upon) <xsl:variable name="qaa">""''</xsl:variable> <xsl:value-of select="translate($foo,'“”‘’',$qaa)"/> > <!-- string contains linefeed --> > <xsl:when test="contains($StringToTransform,' ')"> > <xsl:value-of select="substring-before($StringToTransform,' ')" /> > <br></br> OK, for this you do need a recursive template. 7. (your solution) Use the techique I demonstrate at http://skew.org/xml/stylesheets/linefeed2br/ The lf2br template takes a string in and returns a result tree fragment (special node tree) out. So thereafter you must not treat it like a string; if you put it in a variable, use xsl:copy-of to retrieve it, not xsl:value-of. I would do the translate() first, and pass that string in as the $StringToTransform, like this: <xsl:call-template name="lf2br"> <xsl:with-param name="StringToTransform" select="translate($foo,'“”‘’',$qaa)"/> </xsl:call-template> > <!-- string contains carriage return --> > <xsl:when test="contains($StringToTransform,' ')"> 8. (FYI) You do not ever need to test for CR because all CR+LF and CR are normalized to LF during XML parsing. The only exception is in attribute values where the character reference " " or "
" is used, in which case you do get the CR, if I recall correctly (it's a very rarely used feature). - 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
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] How to Replace Special Charac, Rohitav Samanta | Thread | [xsl] Building html table from atri, Jarkko . Moilanen |
RE: [xsl] Repost: How to make names, Michael Kay | Date | RE: [xsl] Formatting Question, Charles Knell |
Month |