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 19:20:51 +0200 |
I found a solution to my problem ... As I said in the first message the node-set variable is generated in the xsl from the string "/foo/bar[1], /foo/bar[2], /foo/bar[3]/baz[1]" passed as parameter to the xsl. So instead of generating a node-set variable (in order to iterate it and applying template for each value), I directly apply the good templates within a recursiv template which treat the STRING "/foo/bar[1],/foo/bar[2], /foo/bar[3]/baz[1]" (coma separated list) <xsl:param name="MyXpathString" select="'/foo/bar[1],/foo/bar[2],/foo/bar[3]/baz[1]'"/> <xsl:template match="/"> <xsl:call-template name="ApplyTemplateForEachXpath"> <xsl:with-param name="XpathString" select="$MyXpathString"/> </xsl:call-template> </xsl:template> <xsl:template name="ApplyTemplateForEachXpathInStringXpath"> <xsl:param name="XpathString"/> <xsl:choose> <xsl:when test="contains($XpathString,',')"> <xsl:apply-templates select="dyn:evaluate(.,substring-before($XpathString,','))"/> <xsl:call-template name="ApplyTemplateForEachXpathInStringXpath"> <xsl:with-param name="XpathString" select="substring-after($XpathString,',')"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="dyn:evaluate(.,$XpathString)"/> </xsl:otherwise> </xsl:choose> </xsl:template> It works well, and no need of node-set, It's not a solution the problem I had (I don't even know if there's one) and the subject of this post but I can now go on with my code so I'll keep this. Regards, Matthieu. -----Message d'origine----- De : Matthieu Ricaud [mailto:matthieu.ricaud@xxxxxxx] Envoyi : mercredi 26 octobre 2005 17:00 @ : xsl-list@xxxxxxxxxxxxxxxxxxxxxx Objet : RE: [xsl] Dynamicaly applying templates from a node-set containing xpath values - with msxml parser 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Dynamicaly applying templ, Matthieu Ricaud | Thread | Re: [xsl] Dynamicaly applying templ, Ragulf Pickaxe |
Re: [xsl] Help getting started with, David Carlisle | Date | RE: [xsl] Reporting line numbers, Michael Kay |
Month |