[Top] [All Lists]

Re: [xsl] LF and serialize()?

2019-10-25 08:22:21
Am 25.10.2019 um 15:08 schrieb Martin Honnen 
Am 25.10.2019 um 15:04 schrieb Birnbaum, David J djbpitt(_at_)pitt(_dot_)edu:
When I run serialize() (in Saxon-HE XSLT) over an XML
snippet, it does what I need, except that it replaces LF inside
attribute values with SP. This seems to be consistent with what I
read at https://www.w3.org/TR/REC-xml/#AVNormalize, and the
workaround described there (use a numerical character reference to LF
instead of the raw LF character) works. But I’d like to avoid having
to specify in the XML something that I would prefer to manage during
the XSLT transformation, and I would also like to avoid
pre-processing the XML outside an XML environment and replacing the
LF with a numerical character reference there, before passing the
modified XML into the XSLT transformation.

So: Would anyone happen to know of a way within just an XSLT
stylesheet to retain LF within an attribute value as distinct from SP
in the output of serialize()?

What is an XML snippet? Are you sure it is the serialization that
converts linefeeds to spaces or just the XML parsing (that is also what
the spec you cite refers to)?

To illustrate, this XSLT snippet with XSLT 3 constructs some XML with an
attribute value containing line feeds and Saxon, when using the
"serialize" function, rightly then escapes them as numeric character
references, so

    <xsl:variable name="xml-snippet">
            <xsl:attribute name="att1">Line 1.
Line 2.
Line 3.</xsl:attribute>
    <xsl:value-of select="serialize($xml-snippet, map { 'method' :
'xml' })"/>


<element att1="Line 1.&#xA;Line 2.&#xA;Line 3."/>

But of course serialize doesn't convert spaces any previous parsing step
has introduced back to line feeds.

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com

<Prev in Thread] Current Thread [Next in Thread>