Is there a way to modify the following XPath expression to return the number of previous "like" elements? I need a relative count of the number of like nodes in a given branch (I think it's a branch...) This is being used in MS InfoPath:
count(../preceding-sibling::*) + 1
I believe that the structure of my sample XML prevents this from behaving as intended. You will note that all the "Count" values in my XML have the number 1. The DateRepeaterCounter
value should reset in a new MasterRepeater
node and the MasterRepeaterCounter
should reflect the overall number of MasterRepeater
nodes.
I have yet to overcome the learning curve with XPath.
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.25" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\e1d38b31bb224d94\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?>
<my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2012-09-07T14:19:10" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:PrimarySection>
<my:MasterRepeater>
<my:MasterRepeaterCounter>1</my:MasterRepeaterCounter>
<my:DateSection>
<my:DateRepeater>
<my:Date>2012-09-12</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater>
<my:DateRepeater>
<my:Date>2012-09-13</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater>
<my:DateRepeater>
<my:Date>2012-09-14</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater>
</my:DateSection>
</my:MasterRepeater>
<my:MasterRepeater>
<my:MasterRepeaterCounter>1</my:MasterRepeaterCounter>
<my:DateSection>
<my:DateRepeater>
<my:Date>2012-09-15</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater>
<my:DateRepeater>
<my:Date>2012-09-16</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater><my:DateRepeater>
<my:Date>2012-09-17</my:Date>
<my:DateRepeaterCounter>1</my:DateRepeaterCounter>
</my:DateRepeater>
</my:DateSection>
</my:MasterRepeater>
</my:PrimarySection>
</my:myFields>
EDIT & ANSWER
InfoPath was messing up the expression somehow... After entering the expression in one field and then copying it into another it stopped working correctly. Upon re-entering the epxression as formatted above, it resolved the issue. I will self answer when StackOverflow allows it. Thanks!
I'll self answer this one as it turned out to be an InfoPath issue and not an XPath issue. InfoPath was messing up the expression somehow... After entering the expression in one field and then copying it into another it stopped working correctly. Upon re-entering the epxression as formatted above, it resolved the issue. Thanks for all your help!