I have been running around in circles with this. I would like to count the number of workers that have at least one attribute changing. If the first name changes, thats 1. If last name changes, thats 1. If both changes, thats 1.
In my system, change is represented by a node having prior value - similar to below (pseudo):
<!-- XML -->
<Slave_Group>
<Slave>
<Personal>
<First_Name PriorValue="John">Jacob</First_Name>
<Last_Name>Smith</Last_Name>
</Personal>
</Slave>
<Slave>
<Personal>
<First_Name>Mary</First_Name>
<Last_Name PriorValue="Peterson">O'Reilly</Last_Name>
</Personal>
</Slave>
<Slave>
<Personal>
<First_Name PriorValue="Tim">Eric</First_Name>
<Last_Name PriorValue="Heidecker">Wareheim</Last_Name>
</Personal>
</Slave>
</Slave_Group>
The following XSLT is applied to the XML:
<!-- XSLT -->
<variable name="numNameChanges" select="count(//Slave_Group/Slave/Personal/(First_Name[@PriorValue] or Last_Name[@PriorValue]))"/>
The value I would like to get would be numNameChanges = 3. This is not the case. I am getting strange results when I run on the sample file. I am prepared to use a template and count the return of that template - but I am not sure what to match for etc... I have also thought about grouping but I think my spec is not so complicated that I need to get into complex functionality. Maybe I'm being naive.
Is there a way to conditionally count the nodes?
You have several syntax issues in there, most notably redundant parentheses and Prior_Value
instead of PriorValue
. Try:
count(/Slave_Group/Slave[Personal/First_Name/@PriorValue or Personal/Last_Name/@PriorValue])