This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Converting a string to a node and changing the scope
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "James Shaw" <hertzsprrrung at hotmail dot com>
- Cc: XSL-List at lists dot mulberrytech dot com
- Date: Wed, 12 Jun 2002 14:51:32 +0100
- Subject: Re: [xsl] Converting a string to a node and changing the scope
- Organization: Jeni Tennison Consulting Ltd
- References: <F161EkKkD2nFWWaOkBd0001d256@hotmail.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
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