RE: [xsl] Selecting First Letter

Subject: RE: [xsl] Selecting First Letter
From: "Jeffrey Winter" <JeffreyWinter@xxxxxxx>
Date: Thu, 2 Oct 2003 16:10:43 -0400
.. 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 match="node()|@*">
      <xsl:apply-templates select="node()|@*"/>

  <!-- finds the first non-whitespace text() node within the content
       and creates a <b class="firstletter"> element around it -->

  <xsl:template match="text()">
    <xsl:variable name="depth">
      <xsl:number level="any" from="content"
      <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:value-of select="."/>

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:

Current Thread