0

can i call a xsl function inside a function? I just want to compare the previous value and current value. for example:

<xsl:value-of select="//row[(position()-1)]/MONTH_ID" />

but, the code below is ok:

<xsl:value-of select="number(position())-1" />
2
  • this code is ok: <xsl:value-of select="number(position())-1" /> Commented Jul 17, 2013 at 7:37
  • Are you actually trying to find out the value of the MONTH_ID element from the previous row element? It would probably help if you showed a sample of the XML, and the result you are trying to achieve. Thanks! Commented Jul 17, 2013 at 7:43

2 Answers 2

5

The answer to your question is yes, but I don't think you are asking the right question. You haven't said what you are trying to do, but your code sample doesn't do anything useful.

//row[(position()-1)]/MONTH_ID

When a number N is used in a predicate, it means [position()=N], so your predicate means [position() = position() - 1], which will always be false.

I think you are forgetting that the result of position() is sensitive to context, and the context inside a predicate is not the same as the context outside. The answer is to bind a variable:

<xsl:variable name="p" select="position()"/>
<xsl:value-of select="//row[$p - 1]/MONTH_ID"/>
Sign up to request clarification or add additional context in comments.

Comments

1

Yes, you can nest XPath function. Below you can find an example:

substring(child::randlist/item[position()=1], 1, 10)

function position is called inside substring function.

Can you be more specific with comparison request?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.