Subject: Re: [xsl] Transforming field when parsing XML file with xsltproc From: "H agents@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Sun, 3 Jul 2022 20:24:24 -0000 |
On 07/03/2022 10:39 AM, C. M. Sperberg-McQueen cmsmcq@xxxxxxxxxxxxxxxxx wrote: > "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 > > > Thank you, worked great!
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Transforming field when p, C. M. Sperberg-McQue | Thread | [xsl] [ANN] BALISAGE OPEN MIC - In, B Tommie Usdin btusd |
Re: [xsl] Transforming field when p, H agents@xxxxxxxxxxx | Date | [xsl] [ANN] BALISAGE OPEN MIC - In, B Tommie Usdin btusd |
Month |