|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Correcting misplaced spaces in XML documents
On Sun, Mar 26, 2023 at 01:33:59AM -0000, Trevor Nicholls trevor@xxxxxxxxxxxxxxxxxx scripsit:
> Can anyone point me to a cleaner way of doing it?
Something like
<xsl:template match="text()[not(preceding-sibling::node())][not(following-sibling::node())]">
<xsl:value-of select="normalize-space(.)"/>
</xsl:template>
<xsl:template match="text()[preceding-sibling::node()][following-sibling::node()]">
<xsl:value-of select="concat(' ',normalize-space(.),' ')"/>
</xsl:template>
<xsl:template match="text()[not(preceding-sibling::node())][following-sibling::node()]">
<xsl:value-of select="concat(normalize-space(.),' ')"/>
</xsl:template>
<xsl:template match="text()[preceding-sibling::node()][not(following-sibling::node())]">
<xsl:value-of select="concat(' ',normalize-space(.))"/>
</xsl:template>
May be useful. "node()" is dangerous; PIs and comments (if present in
the source) need to be handled as though they aren't there while not
being lost, so the pattern gets more complicated.
And there might be cases where you're trying to do something specific
and different, but that can usually be moved into its own pass, either
before, to regularize the source, or after, to apply the special cases.
--
Graydon Saunders | graydonish@xxxxxxxxx
^fs oferiode, pisses swa mfg.
-- Deor ("That passed, so may this.")
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








