RE: [xsl] saving in one if loop and using it in another

Subject: RE: [xsl] 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
Thanks a lot, Paul. It works...


From: "Clapham, Paul" <pclapham@xxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE: [xsl] 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: [xsl] 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