RE: [xsl] preserving count function when adding template

Subject: RE: [xsl] preserving count function when adding template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 19 Apr 2006 17:25:04 +0100
Change

<xsl:value-of select="name"/>

to

<xsl:apply-templates select="name"/> 

so that template rules are invoked on the name element and its children,
recursively.

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Tom Wern [mailto:twern@xxxxxxxxx] 
> Sent: 19 April 2006 17:14
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] preserving count function when adding template
> 
> I have a simple template, see below:
> 
> <xsl:stylesheet 
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
>      <xsl:template match="node">
>          <div style="text-indent:{count(ancestor-or-self::node)*2}em">
>              <xsl:value-of select="name"/>
>          </div>
>          <br/>
>          <xsl:apply-templates select="node"/>
>      </xsl:template>
> </xsl:stylesheet>
> 
>   that takes a nodeset such as the following:
> 
> <node>
>      <id>123456789</id>
>      <name>COMPANY ABC</name>
>      <node>
>          <id>456789123</id>
>          <name>COMPANY<exist:match>XYZ</exist:match></name>
>      </node>
> </node>
> 
> and simply lists the names, indented corresponding to their 
> nested level. 
> In the example above the list would simply be:
> 
> COMPANY ABC
>        COMPANY XYZ
> 
> What my problem is that I would like to add a template of the form:
> 
> <xsl:template match="exist:match">
>     <span style="background-color: #FFFF00">
>      ???
>     </span>
> </xsl:template>
> 
> to the above stylesheet so as to "highlight" in color the 
> term tagged in the nodeset with <exist:match>.
> 
> How would I integrate this template and what would I specify 
> for ??? to accomplish this?
> 
> All the variations that I have tried do nothing (I can get 
> highlighting but am not able to maintain the indent in the 
> output), but as a newcomer to XSLT I've probably missed 
> something obvious. Could someone please point me in the right 
> direction?
> 
> Thank you.

Current Thread