Counting variable-stored elements in XSLT?

Viewed 35

The value in the XML for D_Payment_Amount_1 passed to the XSLT is a 401KL deduction amount. Each record may or may not pass a value. This sets the variable amount in the XSLT:

<xsl:variable name="counter3" select="Export/Record[ (D_Payment_Amount_1 > 0) ]"/>

I can't quite figure out what is being put into the variable since the select is T or F test. Further on in the code there is a test (<xsl:if test="count($counter3) > 0">).

I guess what's confusing me is the name of the variable, $counter3. If the data amount is greater than 0, is the amount being loaded into the variable or is a 1 (basically a count) being added?

1 Answers

I can't quite figure out what is being put into the variable since the select is T or F test.

No, the select XPath will set counter3 to the node set (XSLT 1.0) or sequence (XSLT 2.0 and up) of Record elements with an Export parent (immediately beneath the current node) and a D_Payment_Amount_1 child whose value is greater than 0.

Then, count() will return the number of those Record elements so that the xsl:if can conditionally execute its code when that count is greater than 0.

The counter3 variable is poorly named.

Related