A
Andy Jefferies
I'm having problems stripping out the whitespace at the beginning of a
particular element. In the XML snippet I've highlighted tabs and returns
as ^I and ^M respectively:
<para> ^I ^I ^I^M
Some text with occasional highlighting. Some text with occasional^M
highlighting. Some text with occasional <high>highlighting</high>.^M
Some text with occasional highlighting. Some <high>text</high> with^M
occasional highlighting.</para>^M
I'd like my XSL to remove all whitespace immediately following <para> and
convert all other ^M's to a single space. My attempt:
<xsl:template match="para">{P}<xsl:apply-templates/>{\P}</xsl:template>
<xsl:template match="high">{B}<xsl:apply-templates/>{\B}</xsl:template>
<xsl:template match="text()"><xsl:value-of select="normalize-space()"/>
</xsl:template>
Strips out too much white space:
{P}Some text with occasional highlighting. Some text with occasional
highlighting. Some text with occasional{B}highlighting{\B}. Some
text with occasional highlighting. Some{B}text{\B}with occasional
highlighting.{\P}
Where the spaces are lost around the highlighting. I understand why it's
happening but can't fix it. Adding spaces around {B} and {\B} in the XSL
helps to some extent, but breaks if the highlighting is at the beginning
or end of <para> and around punctuation.
Could somebody help me make it more selective?
Many thanks,
Andy.
particular element. In the XML snippet I've highlighted tabs and returns
as ^I and ^M respectively:
<para> ^I ^I ^I^M
Some text with occasional highlighting. Some text with occasional^M
highlighting. Some text with occasional <high>highlighting</high>.^M
Some text with occasional highlighting. Some <high>text</high> with^M
occasional highlighting.</para>^M
I'd like my XSL to remove all whitespace immediately following <para> and
convert all other ^M's to a single space. My attempt:
<xsl:template match="para">{P}<xsl:apply-templates/>{\P}</xsl:template>
<xsl:template match="high">{B}<xsl:apply-templates/>{\B}</xsl:template>
<xsl:template match="text()"><xsl:value-of select="normalize-space()"/>
</xsl:template>
Strips out too much white space:
{P}Some text with occasional highlighting. Some text with occasional
highlighting. Some text with occasional{B}highlighting{\B}. Some
text with occasional highlighting. Some{B}text{\B}with occasional
highlighting.{\P}
Where the spaces are lost around the highlighting. I understand why it's
happening but can't fix it. Adding spaces around {B} and {\B} in the XSL
helps to some extent, but breaks if the highlighting is at the beginning
or end of <para> and around punctuation.
Could somebody help me make it more selective?
Many thanks,
Andy.