This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

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


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@hotmail.com]
Sent: July 27, 2001 13:40
To: xsl-list@lists.mulberrytech.com
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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]