Subject: Re: preserving count function when adding template
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 19 Apr 2006 22:03:38 +0530
|
I guess you need something like this
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:exist="whatever" version="1.0">
<xsl:template match="node">
<div style="text-indent:{count(ancestor-or-self::node)*2}em">
<xsl:choose>
<xsl:when test="name/exist:match">
<xsl:value-of select="name/text()"/>
<xsl:apply-templates select="name/exist:match"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="name"/>
</xsl:otherwise>
</xsl:choose>
</div>
<br/>
<xsl:apply-templates select="node"/>
</xsl:template>
<xsl:template match="exist:match">
<span style="background-color: #FFFF00">
<xsl:value-of select="." />
</span>
</xsl:template>
</xsl:stylesheet>
Regards,
Mukul
On 4/19/06, Tom Wern <twern@xxxxxxxxx> wrote:
> 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.
|