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

RE: saving in one if loop and using it in another

Subject: RE: saving in one if loop and using it in another
From: "john smith" <john_smith73@xxxxxxxxxxx>
Date: Sun, 29 Jul 2001 18:44:26 +0000
if loop
Thanks a lot, Paul. It works...


From: "Clapham, Paul" <pclapham@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  saving in one if loop and using it in another
Date: Fri, 27 Jul 2001 14:30:35 -0700

You could use a variable, but setting it up inside the for-each would be a
bad idea for several reasons. First, you talk as if the for-each were a
loop that was executed for position 1, 2, and so on. That isn't guaranteed
to be the case, and it's unhelpful to think of it that way. And second, the
variable is going to be out of scope. Fortunately, your requirement can
easily be recast as "I want to use the first INPUT/*/descendant::* element",
so you could create a variable before the for-each:


<xsl:variable name="first" select="name(INPUT/*/descendant::*[1])"/>

and also before the for-each do everything you wanted to do for the "first"
element:

<PATH>
  <xsl:value-of select="$first"/>
</PATH>

after which your for-each reduces to

<xsl:for-each select="INPUT/*/descendant::*">
  <xsl:element name="APPLY">
    <xsl:if test="position() != 1">
      %%%%%%%%%%
    </xsl:if>
  </xsl:element>
</xsl:for-each>

If my XPaths aren't quite right, I apologize and provide the excuse in
advance that I would likely have to debug it for a while to get it right.
No doubt the experts can fix it up if you can't.  But I don't know your
exact requirements, so at least this may lead you towards the light.

PC2

-----Original Message-----
From: john smith [mailto:john_smith73@xxxxxxxxxxx]
Sent: July 27, 2001 13:40
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  saving in one if loop and using it in another


Given the following:


<xsl:for-each select="INPUT/*/descendant::*">
  <xsl:element name="APPLY">
    <xsl:if test="position() != 1">
      %%%%%%%%%%
    </xsl:if>
    <xsl:if test="position() = 1">
      <PATH>
        <xsl:value-of select="(name())"/>
      </PATH>
    </xsl:if>
  </xsl:element>
</xsl:for-each>

I want to save the name of the node inside the position() = 1 if loop  and
be able to use its value in the %%%%%%%%%% line (where the position() is !=
1)....How can I do it? Can I use the <xsl:variable> or <xsl:param> to save
the name of the node and then use it? If so, how?

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



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.