Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding a value to a variable

Status
Not open for further replies.

LuckyKoen

Programmer
Feb 14, 2005
57
BE
I want to assign the position of the first my-element that is greater than $start-position. However, the following code adds the position of every element to the variable's value and I end up with a long list of numbers. How do I only select the first position() ?

Code:
<xsl:variable name = "my-position"
      <xsl:for-each select="//my-element">
        <xsl:if test="position() &gt; $start-position">       
          <xsl:value-of select = "position()"/>
        </xsl:if>
      </xsl:for-each>   
</xsl:variable>
 
what you are doing is looping through all the my-element 's and assigning all the values to the variable. try this:


<xsl:variable name = "my-position">
<xsl:value-of select="//my-element[position()&gt; $start-position ]/position()">
</xsl:variable>
 
Simon, I got an error when adding the /position() after the condition : "Name or Nodetype test expected: "

Without it the code works though :

<xsl:value-of select="//my-element[position()&gt; $start-position ]"/>



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top