At Thu, 10 Jul 2014 07:52:08 +0200,
Thomas Scheffler wrote:
>
> Am 09.07.2014 16:09, schrieb Vicky Phillips:
> > Hi,
> > We seem to be losing the whitespace when formating xml e.g.
> >
> > <nonSort>Yr </nonSort>
> > <title>Annibynwr</title>
> >
> > becomes
> >
> > <nonSort>Yr</nonSort>
> > <title>Annibynwr</title>
> >
> > Any suggestions as to what we should do in order to retain this whitespace?
>
> Hi,
>
> try this:
>
> <nonSort xml:space="preserve">Yr </nonSort>
>
> It should work this way. But it finally depends on the quality of your
> XML formatting tool.
>
I'm pretty sure that @xml:space does not help here, either. This
attribute is also about whitespace-only nodes.
The question is not: "What should we do to retain this whitespace?" but
rather "Why is trailing the whitespace removed in the first place?".
Apply the following XSL:
,----
| <?xml version="1.0" encoding="utf-8"?>
| <xsl:transform version="1.0"
| xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
| <xsl:strip-space elements="*"/>
| <xsl:template match="node()">
| <xsl:copy>
| <xsl:apply-templates select="node()"/>
| </xsl:copy>
| </xsl:template>
| </xsl:transform>
`----
To this XML:
,----
| <foo>
| <bar>Foobar </bar>
| </foo>
`----
For Saxon-HE 9.4.0.4N you get:
,----
| <?xml version="1.0" encoding="UTF-8"?><foo><bar>Foobar </bar></foo>
`----
With @xml:space
,----
| <foo xml:space="preserve">
| <bar>Foobar </bar>
| </foo>
`----
For Saxon-HE 9.4.0.4N you get:
,----
| <?xml version="1.0" encoding="UTF-8"?><foo>
| <bar>Foobar </bar>
| </foo>
`----
The whitespace-only nodes are preserved.
HTH,
-- David
> regards,
>
> Thomas
>
> --
> Thomas Scheffler
> Friedrich-Schiller-Universität Jena
> Thüringer Universitäts- und Landesbibliothek
> Bibliotheksplatz 2
> 07743 Jena
> Phone: ++49 3641 940027
> FAX: ++49 3641 940022
--
David Maus
Herzog August Bibliothek - D-38299 Wolfenbuettel
Bibliothekarische IT / Digital Humanities
Phone: +49-5331-808-317
Email: [log in to unmask]
PGP Key 0x7B4F5A762AF6FBA6
Fingerprint DD38 8D2E 34C1 94DE 2058 69BE 7B4F 5A76 2AF6 FBA6
|