[xsl] match nodes based on given path

Subject: [xsl] match nodes based on given path
From: "Andrew Welch" <AWelch@xxxxxxxxxxxxxxx>
Date: Thu, 10 Apr 2003 12:20:54 +0100
(tricky)

Hi,

Given an element path of the form:

/root/node/value

How can I override the usual <value> matching template with a special template, only when <value>'s path matches the given path?

To expand it a little, take the xml snippet:

<root>
  <node>
    <value>foo</value>
  </node>
</root>

And the stylesheet:

<xsl:stylesheet version="1.0" 
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:param name="externalLinks">
  <link path="/root/node/value"/>
  <link path="/root/value"/>
</xsl:param>

<xsl:template match="value">
  <xsl:value-of select="'usual'"/>
</xsl:template>

<xsl:template name="special">
  do something extra
</xsl:template>

</xsl:stylesheet>

Here, as the <value> elements path matches that given in the parameter I would like to apply the special template, and then the usual one.  The paths could point to any element, so I need to somehow apply templates based on the paths, generating the output in the result tree in the position that it would appear normally (I can't just bolt it onto the end with an 'eval').

This is more tricky than it initally looks.  I'm currently using an importing stylesheet that tests every element's path against those in the parameter, which is far from efficient and requires the paths to be in some kind of normal form.

Has anyone got any ideas to improve this?  Im thinking about creating a stylesheet that generates templates with match attributes based on the paths, and then including them at the foot of the original stylesheet... however I may be missing something more obvious.

cheers
andrew



---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.470 / Virus Database: 268 - Release Date: 08/04/2003
 

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


Current Thread