Nguyen Dang
Nguyen Dang

Reputation: 11

can i call xslt function inside another function

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" />

Upvotes: 0

Views: 1381

Answers (2)

Michael Kay
Michael Kay

Reputation: 163587

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"/>

Upvotes: 5

Federico Viotti
Federico Viotti

Reputation: 69

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?

Upvotes: 1

Related Questions