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

Re: removing final space from node tree

Subject: Re: removing final space from node tree
From: Andrew Welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 20 Apr 2009 23:07:07 +0100
Re:  removing final space from node tree
>  <!-- We need to remove any extraneous final spaces. -->
>  <!-- set context node to language-desc -->
>  <xsl:for-each select="$language-desc">
>    <!-- find last text node in descendants -->
>    <xsl:variable name="last-text-node" select="(.//text())[last()]"/>
>      <xsl:choose>
>        <xsl:when test="ends-with($last-text-node, ' ')">
>          <xsl:apply-templates mode="strip-final-space" select=".">
>            <xsl:with-param name="last-text-node"
>                select="$last-text-node"/>
>            </xsl:apply-templates>
>        </xsl:when>
>        <xsl:otherwise><xsl:sequence select="."/></xsl:otherwise>
>      </xsl:choose>
>    </xsl:for-each>
>
> ...
>
>    <!-- copy the context node tree, removing final space from the node
> that is passed as a parameter. -->
>    <xsl:template mode="strip-final-space" match="@*|node()">
>        <xsl:param name="last-text-node" />
>        <xsl:choose>
>            <xsl:when test=". is $last-text-node"><xsl:value-of
> select="substring(., 1, string-length(.) - 1)"/></xsl:when>
>            <xsl:otherwise>
>                <xsl:copy>
>                    <xsl:apply-templates mode="strip-final-space"
> select="@*|node()">
>                        <xsl:with-param name="last-text-node"
> select="$last-text-node"/>
>                    </xsl:apply-templates>
>                </xsl:copy>
>            </xsl:otherwise>
>        </xsl:choose>
>    </xsl:template>


I think this would do the same job:

<xsl:template match="text()">
  <xsl:value-of select="if (. is
/path/to/lanuguage-desc/descendant::text()[last()][ends-with(., ' ')])
then
      substring(., 1, string-length(.) - 1) else ."/>
</xsl:template>



--
Andrew Welch
http://andrewjwelch.com
Kernow: http://kernowforsaxon.sf.net/

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-2011 All Rights Reserved.