| 
 
Subject: Re: [xsl] Converting a string to a node and changing the scope From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Wed, 12 Jun 2002 14:51:32 +0100  | 
Hi James,
> 1) I am passing a string as a parameter into a template. Can I treat
> the string as if it were a reference to a node.
Not in standard XSLT/XPath. Many processors have extensions that
enable you to evaluate a string as an XPath expression, however. For
example saxon:evaluate() or dyn:evaluate() from EXSLT:
  <xsl:value-of select="dyn:evaluate($mystring)" />
Have a look at your processor documentation to work out whether your
processor supports something like this; even if it doesn't, you might
be able to write one of your own using DOM methods.
  
> 2) I realise that xsl:for-each will change the current scope.
> However, if I wanted to call a template, but in a different scope,
> is there a proper way of changing the scope?
You could wrap the call to the template within a xsl:for-each, I
suppose. However, usually when the current node matters to a template,
I make it a matching template rather than a named template, with a
mode to distinguish it from other templates, and then apply templates
to the node that I want to process. Or you could pass the node as a
parameter if you prefer. For example, rather than:
  <xsl:for-each select="somenode">
    <xsl:call-template name="sometemplate" />
  </xsl:for-each>
you could do:
  <xsl:apply-templates select="somenode" mode="sometemplate" />
or:
  <xsl:call-template name="sometemplate">
    <xsl:with-param name="node" select="somenode" />
  </xsl:call-template>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
  | 
| <- Previous | Index | Next -> | 
|---|---|---|
| [xsl] Converting a string to a node, James Shaw | Thread | RE: [xsl] Converting a string to a , Michael Kay | 
| [xsl] node() as pattern, DPawson | Date | Re: [xsl] node() as pattern, Jeni Tennison | 
| Month |