Re: [xsl] loop without switching context

Subject: Re: [xsl] loop without switching context
From: Fred Christian <fchristian@xxxxxxxxxxxxxxxxxxxxxx>
Date: Fri, 23 Mar 2012 14:44:34 -0700
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.


On Fri, Mar 23, 2012 at 9:02 AM, Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
> 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
> 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@xxxxxxxxxxxxxxxx
> Mulberry Technologies, Inc.      
> 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
> ==================================================================

Current Thread