xsl-list
[Top] [All Lists]

Re: [xsl] loop without switching context

2012-03-23 16:45:12
Thanks Wendell, Michael and David,

I was able to learn a bit from each answer.

I got my transform working by using the proper form
    <xsl:variable name="x" select="."/>
instead of
    <xsl:variable name="x"><xsl:copy-of select="."/></xsl:variable>

I think I will finally brake that habit from my msxsl xslt 1.0 days.

And I can see your point about the term "loops". It can set up a
misunderstanding. One that I have helped others though while teaching
xslt, so I should know better.

Thanks,
Fred

On Fri, Mar 23, 2012 at 9:02 AM, Wendell Piez 
<wapiez(_at_)mulberrytech(_dot_)com> wrote:

Hi Fred,

First off (this is totally minor) there are those among us who get nervous 
when people refer to "loops" in XSLT, which they really aren't. (I realize 
that even loops aren't loops, but still.)

For the main business:


On 3/22/2012 7:36 PM, Fred Christian wrote:

The loop works, but it switches my context so that template "a" no
longer has the xml it needs.
I realized I could pass in the context node as a param, but it seems
that is only giving me access to children and not ancestors of the
context node.


The usual solution to your problem is to bind the node needed to a variable 
outside the for-each, so it is available inside it. And, as you say, it can 
be passed as a parameter into any other templates.

When this is done correctly, you do have access to the node, its children and 
ancestors.

This leads me to think something is going wrong in code you aren't showing us.

BTW, you will get better performance, and avoid potential headaches, if 
instead of


<xsl:with-param name="x">01</xsl:with-param>

you say

<xsl:with-param name="x" select="'01'"/>

Cheers,
Wendell

======================================================================
Wendell Piez                           
 mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
 Mulberry Technologies: A Consultancy Specializing in SGML and XML
==================================================================

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--


<Prev in Thread] Current Thread [Next in Thread>