Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to I add extra condition on my xslt count when statement? 1

Status
Not open for further replies.

momo2000

Programmer
Jan 2, 2015
63
US
I have a when statement that I would like to add one more condition.
I would like to add CaseParty with an Op='A' to my existing count.
How do I do that?

Here is my xslt when test count statement
Code:
 <xsl:when test="(count(CaseParty[((ObservedRace/@Op='E') or (ObservedEthnicity/@Op='E')) and (Connection/@Word='RSP')] )>0)">

Here is my xml document
XML:
<Integration>
	<Case>
	     <CaseParty ID="7470">
			<ObservedRace Word="W" Op="E">White</ObservedRace>
			<ObservedEthnicity Word="NH">Non Hispanic</ObservedEthnicity>
			<Connection Word="RSP"/>
		</CaseParty>
		<CaseParty ID="111" Op="A">
			<Connection Op="A" Word="CHD">
				<Description>Child</Description>
			</Connection>
		</CaseParty>
	</Case>
</Integration>
 
If I understand correctly that you would like to count both of the CaseParty nodes in the XML fragment, then use the union operator. The count() function is counting the number of nodes in a nodeset that is described by an XPath expression. If we increase the number of nodes in the nodeset by using the union operator, the count will increase. So, the following is simplified for clarity:
Code:
count( CaseParty[[i]condition-1[/i]] [b]|[/b] CaseParty[[i]condition-2[/i]] )
The condition you already have would be condition-1, and condition-2 could be simply [tt]@Op='A'[/tt].

If a node meets both conditions, it is only counted once (this is the nature of a union operation).

The union operator also provides a means to select nodes with different names. or even different types of nodes. You will see the union operator used prominently in identity transforms.

Tom Morrison
Hill Country Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top