[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

loop without switching context

Subject: loop without switching context
From: Fred Christian <fchristian@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Mar 2012 16:36:23 -0700
 loop without switching context
I ran into a challenge today that I ended up working around.
I wonder though if there is a direct solution.

Is there a way to write a loop without switching context?
I am using XSLT 2.0 and Saxon.

If I loop through a set of values using <xsl:for-each> then my context
is set to the xml that contains that data. But I want my context to be
set to the xml before I entered the for-each.

Some example code.
I had this.
<xsl:call-template name="a"><xsl:with-param
name="x">01</xsl:with-param></xsl:call-templates>
<xsl:call-template name="a"><xsl:with-param
name="x">02</xsl:with-param></xsl:call-templates>
{duplicated about 10 times}

It works okay, but it is hard-coded (bad).
I will have cases where my list of x values will vary, but they will
always be short strings like {01,02,A1,B3}. And the number of values
will always be less than 20.

So I thought of using xsl:for-each on a data file for the x values.
Like this
<xsl:variable name="datafile">../data.xml</xsl:variable>
<xsl:for-each select="document($datafile)/data/xvals/x">
  <xsl:call-template name="a"><xsl:with-param
name="x">01</xsl:with-param></xsl:call-templates>
</xsl:for-each>

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.

Maybe I have hit a case where I am just modeling the project wrong and
need to rethink it some.
Or, is there a way to write a loop without switching context?

Thanks,
Fred

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.