[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|