RE: [xsl] Selecting First Letter

Subject: RE: [xsl] Selecting First Letter
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Tue, 30 Sep 2003 23:09:27 +0100
> In your case, assuming you want the character in bold to be 
> the initial 
> character inside the p, at any level,
> 
> <xsl:template match="text()[not(preceding::text()
>    [count(.|current()/ancestor::p//text()) =
>     count(current()/ancestor::p//text())])]">
> 
> would do it, but you can see how horrible that is!
> 
> Not foolproof, but
> 
> match="text()[starts-with(ancestor::p,.)]"
> 
> would usually work (and would most probably perform better).
> 
> So today's XSLT Challenge is to write a better match for this problem.

I think that

<xsl:variable name="n"><xsl:number level="any" from="p"/></xsl:variable>
<xsl:choose>
<xsl:when test="$n = 1">...

works reasonably, though it can't be done in the match pattern, except
(in XSLT 2.0) by invoking an xsl:function from the predicate.

Michael Kay


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread