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

RE: Selecting First Letter

Subject: RE: Selecting First Letter
From: "Jeffrey Winter" <JeffreyWinter@xxxxxxx>
Date: Thu, 2 Oct 2003 16:10:43 -0400
xsl 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


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