[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Count leading spaces using xpath expression
Hi,
I am looking for a way to count the number of leading spaces in the text of an element. I have written the following template which does this: <xsl:template name="countIndent"> <xsl:param name="str" /> <xsl:param name="leadingSpaces" select="0"/> <xsl:choose> <xsl:when test="(string-length($str) != 0) and (normalize-space(substring($str, 1, 1)) = '' )" > <xsl:call-template name="countIndent"> <xsl:with-param name="str" select="substring($str, 2)" /> <xsl:with-param name="leadingSpaces" select="$leadingSpaces + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$leadingSpaces" /> </xsl:otherwise> </xsl:choose> </xsl:template> However, I'd like to get this information as an xpath expression (so I can use it in a predicate e.g. /myElement[(indent expression) > 3]). Is this possible (it would only have to work for spaces, not all whitespace)? Thanks for any advice. Grainne. XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|