[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

Subject: Re: Transforming field when parsing XML file with xsltproc
From: "C. M. Sperberg-McQueen cmsmcq@xxxxxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 3 Jul 2022 14:40:00 -0000
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(.), '&#x0A;', ' ')"/>
                      
        ... 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(., '&#xA;', ' ')"/>
    </

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

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.