Context

Eliza Zadura

Usenet Archive
Joined
Jul 31, 2003
Messages
10
Reaction score
0
The following question is about XPath and context, as I am not sure I'm grasping the concept entirely and this is causing me some problems while working on my XSL transformation.

I have checked the XPath specification and am somewhat familiar with the different addressing mechanisms. What confuses me is the context when using templates and various (nested) <xsl:for-each>, <xsl:if> and <xsl:when> expressions.

For example, say I have a named template where test-param is the value of a certain node.

<xsl:template name="test_temp">
<xsl:param name="test_param"/>
...
...
<xsl:for-each select="[some other node]">

<!--here, I assume the context is that of [some other node], and not the node represented by test_param?-->

<xsl:if test="[yet another node]">

<!--What about the context here, is it that of [yet another node]?-->

</xsl:if>
</xsl:for-each>

<!--And here, am I back to the original context, the one defined by the test_param?-->

</xsl:template>

And so on, and so forth...
To put it briefly: Does every expression that evaluates a set of nodes change the context to that particular set, thus enabling me to use ./ while referring to attributes or other subnodes of that node?
 

Marrow

Usenet Archive
Joined
Apr 9, 2001
Messages
408
Reaction score
0
Hi Eliza,
For example, say I have a named template where test-param is the value of a certain node.

<xsl:template name="test_temp">
<xsl:param name="test_param"/>

^^^^^ the context here will be whatever the context node was at the point of
the said:
..
..
<xsl:for-each select="[some other node]">

<!--here, I assume the context is that of [some other node], and not the node represented by test_param?-->

^^^^^ yes, the context node will be the [some other node]
<xsl:if test="[yet another node]">

<!--What about the context here, is it that of [yet another node]?-->

</xsl:if>
</xsl:for-each>

<!--And here, am I back to the original context, the one defined by the test_param?-->

^^^^^ No, because the context was never the node(s) in the $test_param - the context will revert to the context node at the point of the
</xsl:template>

Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger) http://www.topxml.com/Xselerator

Eliza Zadura said:
The following question is about XPath and context, as I am not sure I'm grasping the concept entirely and this is causing me some problems while working on my XSL transformation.

I have checked the XPath specification and am somewhat familiar with the different addressing mechanisms. What confuses me is the context when using templates and various (nested) <xsl:for-each>, <xsl:if> and <xsl:when> expressions.

For example, say I have a named template where test-param is the value of a certain node.

<xsl:template name="test_temp">
<xsl:param name="test_param"/>
..
..
<xsl:for-each select="[some other node]">

<!--here, I assume the context is that of [some other node], and not the node represented by test_param?-->

<xsl:if test="[yet another node]">

<!--What about the context here, is it that of [yet another node]?-->

</xsl:if>
</xsl:for-each>

<!--And here, am I back to the original context, the one defined by the test_param?-->

</xsl:template>

And so on, and so forth...
To put it briefly: Does every expression that evaluates a set of nodes change the context to that particular set, thus enabling me to use ./ while referring to attributes or other subnodes of that node?
 

Eliza Zadura

Usenet Archive
Joined
Jul 31, 2003
Messages
10
Reaction score
0
Thank you for your reply. That is what I thought, but I wanted it confirmed.

What about if I have nested for loops? Will the context of the inner loop be that of the inner select?

I'm having to do quite horrible loops and conditions to accomplish what I need, and find all this a bit confusing...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,208
Messages
3,104,799
Members
249,594
Latest member
henrywalsh

Latest Threads

Top