[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Transforming field when parsing XML file with xsl
"H agents@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> writes: > Unfortunately one of the fields of the XML records occasionally > contains LF characters which normally should not be part of the > field. Can xsltproc be used to replace the LF in this single field > with SPACE? If the element 'this-single-field' never has child elements, then something along the lines of <xsl:template match="this-single-field"> <xsl:variable name="safe-value" select="translate(string(.), '
', ' ')"/> ... do what you need to do ... ... and write $safe-value out where you need it ... </ If this-single-field may have child elements, then you need to call translate() on each text node within it. So instead of handling it all at once as shown above, you'll need to handle it text-node by text-node: <xsl:template match="text()[ancestor::this-single-field]"> <xsl:value-of select="translate(., '
', ' ')"/> </ If the line breaks in the input turn out to be important (e.g. people using them to separate paragraphs or items in lists -- it does happen), you might want to translate LF to "\n" instead of " ", and let downstream processes use the \n or not as they choose. Good luck. Michael Sperberg-McQueen -- C. M. Sperberg-McQueen Black Mesa Technologies LLC http://blackmesatech.com
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|