Stripping whitespace around certain elements

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.
 
A

Andy Jefferies

Colin Mackenzie said:
Not sure if this is what you want to do, but it sort of works.

Thanks! There's just one case I've found where this doesn't work but it's
perfectly acceptable until I can invest the time in learning extensions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,989
Messages
2,570,207
Members
46,783
Latest member
RickeyDort

Latest Threads

Top