[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Selecting First Letter
.. If you did <xsl:number level="any" from="content" .. count="text()[normalize-space()]"/> and only handled number .. 1, you'd work .. around the whitespace problem Dimitre cited without having to strip .. whitespace-only nodes (always a dangerous thing in running .. prose). that works too. Thanks for this info. Just to close this thread, and for the edification of those who come after, here is the final snip of the stylesheet that <xsl:template match="entry"> <!-- other stuff --> <xsl:apply-templates select="content/node()"/> <!-- other stuff --> </xsl:template> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*"/> </xsl:copy> </xsl:template> <!-- finds the first non-whitespace text() node within the content element and creates a <b class="firstletter"> element around it --> <xsl:template match="text()"> <xsl:variable name="depth"> <xsl:number level="any" from="content" count="text()[normalize-space()]"/> </xsl:variable> <xsl:choose> <xsl:when test="$depth = 1"> <xsl:variable name="initial" select="substring(.,1,1)"/> <b class="firstletter"><xsl:value-of select="$initial"/></b> <xsl:value-of select="substring-after(.,$initial)"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="."/> </xsl:otherwise> </xsl:choose> </xsl:template> BTW, the reason I was doing this at all is so that I could supply specific styling to the first letter of some text. I realize that there is the :firstletter psuedo class in CSS, but browser support is very inconsistent even in those browsers that support it at all. Anyway, thanks again. .. Ain't this list amazing? It sure is. - Jeff 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
|