-2

I am trying to perform loop A or Loop B based on the count of the nodes

 empjobcount -> "count(employmentNav/EmpEmployment/compInfoNav/EmpCompensation/startDate)"  
 compcount -> "count(employmentNav/EmpEmployment/jobInfoNav/EmpJob/startDate)"

how to pass count to the parameter in order to perform if condition. Below is causing syntax error.

<xsl:if test= {"count(employmentNav/EmpEmployment/compInfoNav/EmpCompensation/startDate)" ge "count(employmentNav/EmpEmployment/jobInfoNav/EmpJob/startDate)"} >
</xsl:if>

Pseudocode: if empjobcount > compcount. loopA. else. loopB. endif.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
Krishna
  • 1
  • 2

1 Answers1

0

Drop the curly braces, i.e. use test="count(employmentNav/EmpEmployment/compInfoNav/EmpCompensation/startDate) >= count(employmentNav/EmpEmployment/jobInfoNav/EmpJob/startDate)". I also think you need xsl:choose/xsl:when test/xsl:otherwise instead of a single xsl:if if you really need to execute two different branches of code.

As you have tagged your question for XSLT 2.0 and XSLT 3.0 it might be possible to solve things at the XPath expression level with the if (conditional expression) then expression1 else expression2 expression e.g.

if (count(employmentNav/EmpEmployment/compInfoNav/EmpCompensation/startDate) >= count(employmentNav/EmpEmployment/jobInfoNav/EmpJob/startDate)) then mf:foo() else mf:bar()

where mf:foo and mf:bar would be user-defined functions set up with xsl:function.

The whole description with talk about loops sounds as if you try to use procedural programming with XSLT, you might want to show us small but representative samples of XML input, output you want together with the rules you want to implement so that we might be able to suggest a more XSLT like approach.

Martin Honnen
  • 160,499
  • 6
  • 90
  • 110