I need to adapt the following XPath expression to return the “Latest” Amend_Start_Date from the sample XML (from MS InfoPath):
//my:Amend_Data[0=count(following-sibling::my:Amend_Data)]//my:Amend_Start_Date
And the XML:
<?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.440" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\1c02663d7ed84d09\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.2"?><?mso-infoPath-file-attachment-present?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2011-05-05T19:56:08" xmlns:xd="http://schemas.microsoft.com/office/infopath/2003" xml:lang="en-us">
<my:MasterSection>
<my:Planning_Section>
<my:Planned_Start_Date>2012-09-12</my:Planned_Start_Date>
<my:Planned_End_Date>2012-09-14</my:Planned_End_Date>
</my:Planning_Section>
<my:Actual_Section>
<my:Actual_Start_Date>2012-09-13</my:Actual_Start_Date>
<my:Actual_End_Date>2012-09-15</my:Actual_End_Date>
</my:Actual_Section>
<my:Amend_Hider>
<my:Amend_Info_Repeater_Group>
<my:Amend_Info_Repeater>
<my:Amend_Data>
<my:Amend_Start_Date>2012-09-16</my:Amend_Start_Date>
<my:Amend_End_Date>2012-09-21</my:Amend_End_Date>
</my:Amend_Data>
</my:Amend_Info_Repeater>
<my:Amend_Info_Repeater>
<my:Amend_Data>
<my:Amend_Start_Date>2012-09-23</my:Amend_Start_Date>
<my:Amend_End_Date>2012-09-27</my:Amend_End_Date>
</my:Amend_Data>
</my:Amend_Info_Repeater>
</my:Amend_Info_Repeater_Group>
</my:Amend_Hider>
</my:MasterSection>
I started using XPath last Thursday… So forgive me if I am in need of spoonfeeding. As it stands the listed expression returns all start date nodes from the sample XML. It is intended to return the “Latest” Amend_Start_Date but does not because the structure of the XML is such that the Amend_Start_Date nodes are not grouped together. In this example that would mean a correct expression would return a start date of 2012-09-23 and NOT 2012-09-16
There must be a way this can be accomplished! Somehow the relative path of the Amend_Data node must be modified… Any help is appreciated!
PS: This relates to a question I posted on Friday that can be found here. You may note the structural difference in the sample XML listed in that question v. this one.
This:
should do the trick.
Without using
last()you can try: