RE: [xsl] Dynamicaly applying templates from a node-set containing xpath values - with msxml parser

Subject: RE: [xsl] Dynamicaly applying templates from a node-set containing xpath values - with msxml parser
From: "Matthieu Ricaud" <matthieu.ricaud@xxxxxxx>
Date: Wed, 26 Oct 2005 17:00:20 +0200
Thank you for your answer Ragulf !
I tried :
<xsl:for-each select="msxsl:node-set($NodeSetXpathNode)/xpath">
  <xsl:variable name="var" select="'/foo/@bar'"/>
  <xsl:value-of select="dyn:evaluate(.,$var)"/>
</xsl:for-each>
I do not get error message anymore, but unfortunately the template is not
applied.
Having no error message is a good step anyway :)

I guess the $var was not a string in my former code, i tried convert it to a
string replacing select="." by select="string(.)" :

<xsl:for-each select="msxsl:node-set($NodeSetXpathNode)/xpath">
       <xsl:variable name="xpathValue" select="string(.)"/>
       <xsl:apply-templates select="dyn:evaluate(.,$xpathValue)"/>
</xsl:for-each>

and that's it ! I don't get error anymore with this code.
(actually I don't really see why... maybe select="." select a text node,
which is not considered as a string ?)

About not using msxsl:node-set extension, I tried without it : for-each
select="$NodeSetXpathNode/xpath" but it failed. I think mxsml parser need to
be explained it is a node set to iterate through, but anyway, this point is
resolved, the question now is why it doesn't apply the template...

When I do :
       <xsl:variable name="xpathValue" select="'/foo/@bar'"/>
       <xsl:apply-templates select="dyn:evaluate(.,$xpathValue)"/>
The template is applied !

When I do the same but within the node-set iteration :
<xsl:for-each select="msxsl:node-set($NodeSetXpathNode)/xpath">
       <xsl:variable name="xpathValue" select="'/foo/@bar'"/>	==> I'll put
string(.) later when it work
       <xsl:apply-templates select="dyn:evaluate(.,$xpathValue)"/>
</xsl:for-each>
The template is not applied !

I think it can only be a "context node" problem ?
here : dyn:evaluate(-->.<--,$xpathValue)

dyn:evaluate is a simple function defined like this :

	<msxsl:script implements-prefix="dyn" language="jscript">
	   function evaluate(context, expression)
	      {
	         return context.nextNode().selectNodes(expression);
	      }
	</msxsl:script>

The first argument should be the context node path from which the expression
(2nd argument) will be evaluate.

Within the node-set iteration, "." represents the iterated node and not any
node of the xml tree.
Is there a way, within the iteration, to come back to another context node,
the root of the xml file for example ?

Any suggestions are welcome,
Thanks,
Matthieu

-----Message d'origine-----
De : Ragulf Pickaxe [mailto:ragulf.pickaxe@xxxxxxxxx]
Envoyi : mercredi 26 octobre 2005 15:56
@ : xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Objet : Re: [xsl] Dynamicaly applying templates from a node-set
containing xpath values - with msxml parser


Hi Matthieu,

I have not the time to look at the function, but

> I think it is because of the context node, which is the matched <xpath>
node
> within the for-each element,

This would be easily tested by combining:
> <xsl:variable name="var" select="'/foo/@bar'"/>
> <xsl:value-of select="dyn:evaluate(.,$var)"/>

With

> <xsl:for-each select="msxsl:node-set($NodeSetXpathNode)/xpath">
>        <xsl:variable name="xpathValue" select="."/>
>        <xsl:apply-templates select="dyn:evaluate(.,$xpathValue)"/>
> </xsl:for-each>

Giving:
<xsl:for-each select="msxsl:node-set($NodeSetXpathNode)/xpath">
  <xsl:variable name="var" select="'/foo/@bar'"/>
  <xsl:value-of select="dyn:evaluate(.,$var)"/>
</xsl:for-each>

If this does not work, then your hypothetis might be correct, but if
it does work, then it will have to be something else. It might then be
the expressions, or it might be something else entirely. You could
perhaps also iterat over a nodeset which is not made using
msxsl-extension, and see what happens here.

These are just a couple of thoughts that might help narrow down your
problem.

Regards,
Ragulf Pickaxe :-)

Current Thread