[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Removing unwanted space
Hi Charles,
As I understand it, you want to normalize space, but exercise the option to specify if the initial or terminal space should be replaced by a single space or removed altogether. Here's how I'd handle it: <xsl:template match="text()" priority="-1" mode="normalize-space"> <!-- By default, normalize initial and terminal space to a single space, but space-normalize all the intervening text. --> <xsl:if test="matches(., '^\s')"> <xsl:value-of select="' '"/> </xsl:if> <xsl:value-of select="normalize-space(.)"/> <xsl:if test="matches(., '\S\s+$')"> <xsl:value-of select="' '"/> </xsl:if> </xsl:template> <xsl:template match="p/text()" mode="normalize-space"> <!-- These tests permit comments and processing instructions to be inserted inside initial or final indentations, without affecting the results. --> <xsl:variable name="is-not-initial-indentation" as="xs:boolean" select=" some $i in (preceding-sibling::* | preceding-sibling::text()) satisfies matches($i, '\S')"/> <xsl:variable name="is-not-final-indentation" as="xs:boolean" select=" some $i in (following-sibling::* | following-sibling::text()) satisfies matches($i, '\S')"/> <xsl:if test="$is-not-initial-indentation and matches(., '^\s')"> <xsl:value-of select="' '"/> </xsl:if> <xsl:value-of select="normalize-space(.)"/> <xsl:if test="$is-not-final-indentation and matches(., '\S\s+$')"> <xsl:value-of select="' '"/> </xsl:if> </xsl:template> Good luck! jk Joel, to answer your question (incompletely), given -- Joel Kalvesmaki Director, Text Alignment Network http://textalign.net
|
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
|