Thursday, July 10, 2008

Variable in XSL

I need count the number of the nodes which have a long long xpath. I am not sure my xpath is correct. I want to display the result of count. How...?

A function could be put in xsl:value-fo directly, like this
<xsl:value-of select="
count(//FIELD[FNAME='exceptionList']
/STRUCT[SNAME='ImagisInterfaceExceptionDetailsList']/FIELD[FNAME='dtls']
/STRUCT_LIST/STRUCT/FIELD[FNAME='type' and VALUE='stopped'])" />


If I need use that function a couple of times, I can use "variable" in xslt.
<xsl:variable name="countResult" select="
count(//FIELD[FNAME='exceptionList']
/STRUCT[SNAME='ImagisInterfaceExceptionDetailsList']/FIELD[FNAME='dtls']
/STRUCT_LIST/STRUCT/FIELD[FNAME='type' and VALUE='stopped'])" />

<xsl:value-of select="$countResult"/>

<xsl:if test="$countResult>0">
<p>display...</p>
</xsl:if>

No comments:

Post a Comment