How to remove unwanted whitespace from an XML element?
Posted: Thu Jan 24, 2008 5:41 pm
I'm using Oxygen 9.1 with Saxon 9B.
I'm creating a Microsoft Word document from the contents of an XML file, using XSLT to process the XML elements and output WordprocessingML tags.
Most of the transformation is going well, but I'm having trouble with mixed text in an element. An example XML element to transform is this one:
When my Description template has:
to process the text, the whitespace before each line of the <Description> gets copied to the output and Word treats it as fixed whitespace, so I get big gaps in the text.
When the Description template has:
then the whitespace is removed, but the formatting tags are also removed so that I don't have a chance to process them.
The XML file with the <Description> elements (and others, of course) is hand-edited and formatted. The Oxygen "Format and Indent" operation formats the <Description> element as above, so I don't really have control over the line breaks in the text.
Question: How do I get rid of the extra whitespace while processing the <Description> tag, and yet be able to process any formatting commands in it?
Thanks, Mike Cook
I'm creating a Microsoft Word document from the contents of an XML file, using XSLT to process the XML elements and output WordprocessingML tags.
Most of the transformation is going well, but I'm having trouble with mixed text in an element. An example XML element to transform is this one:
I invoke my template with:<Description>This is some text for the paragraph. It has some <bold>formatting
tags</bold> in it which I will <bold><italic>process myself</italic> as I
output</bold> the text of this message. This paragraph has more text
here.</Description>
Code: Select all
<xsl:apply-templates select="Description"/>
Code: Select all
<w:r>
<w:t>
<xsl:apply-templates/>
</w:t>
</w:r>
When the Description template has:
Code: Select all
<w:r>
<w:t>
<xsl:value-of select="normalize-space()"/>
</w:t>
</w:r>
The XML file with the <Description> elements (and others, of course) is hand-edited and formatted. The Oxygen "Format and Indent" operation formats the <Description> element as above, so I don't really have control over the line breaks in the text.
Question: How do I get rid of the extra whitespace while processing the <Description> tag, and yet be able to process any formatting commands in it?
Thanks, Mike Cook