[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Correcting misplaced spaces in XML documents

Subject: Re: Correcting misplaced spaces in XML documents
From: "Graydon graydon@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sun, 26 Mar 2023 01:52:20 -0000
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('&#x0020;',normalize-space(.),'&#x0020;')"/>
  </xsl:template>
  <xsl:template match="text()[not(preceding-sibling::node())][following-sibling::node()]">
    <xsl:value-of select="concat(normalize-space(.),'&#x0020;')"/>
  </xsl:template>
  <xsl:template match="text()[preceding-sibling::node()][not(following-sibling::node())]">
    <xsl:value-of select="concat('&#x0020;',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.")

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.