xsl-list
[Top] [All Lists]

RE: match nodes based on given path

2003-04-10 09:27:46

Thanks for the suggestions David - some quite nice techniques there I hadnt 
even considered.  

Im currently using:

<xsl:template match="node()">
  <xsl:choose>
    <xsl:when test="saxon:path() = $indyLinks//locator/@elementPath">
      <xsl:call-template name="IndyLink"/>
      <xsl:apply-imports/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-imports/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

Where $indyLinks is the node-set passed in as a parameter.  Its pretty bad as 
it tests every element's path using saxon:path() (which Im assuming is 
expensive) against those contained the param.  The xsl:apply-imports technique 
is the way to go I think, with the main issue being 'is the the <node> Im 
matching '/root/foo/node' or is it some other <node>'.  saxon:path() provides a 
'normalised' path, and could possibly be free if saxon keeps track of the full 
path rather that evaluting it on request (hopefully Mike can shed some light).  

If you havent guessed already its to implement a form of independent linking, 
where an external file holds the filenames and element paths of the links, and 
the processing stylesheet has to include the link mechanism in the correct 
place in the output.  Its quite an interesting task...

cheers
andrew

 

-----Original Message-----
From: David Carlisle [mailto:davidc(_at_)nag(_dot_)co(_dot_)uk]
Sent: 10 April 2003 16:50
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] match nodes based on given path



Are you committed to this format:

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

as that makes it difficult in standard XSLT 1 as its a RTF so you can
not get at the structire of the parameter at all.

If you had
<xsl:key name="special" match="/root/node/value"/>
<xsl:key name="special" match="/root/value"/>

Then you could have

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


<xsl:template match="key('special')" priority="2">
  do something extra
  <xsl:call-template name="value"/>
</xsl:template>

Rather than 
 <xsl:call-template name="value"/>
which might not be teh right thing to do if you have lots of different
 normal templates you want to call you could instead do

  <xsl:apply-imports/>

and stick all your "normal" templates in a stylesheet 
imported into this
one

David

______________________________________________________________
__________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
______________________________________________________________
__________

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





---
Incoming 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
 


---
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