我需要调整以下XPath表达式,以从示例XML(从MS InfoPath)返回“最新” Amend_Start_Date
:
//my:Amend_Data[0=count(following-sibling::my:Amend_Data)]//my:Amend_Start_Date
和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>
我上周四开始使用XPath ...如果需要汤匙喂,请原谅我。按原样,列出的表达式返回示例XML中的所有开始日期节点。它旨在返回“最新”
Amend_Start_Date
,但不是因为XML的结构使得Amend_Start_Date
节点未分组在一起。在此示例中,这意味着正确的表达式将返回开始日期2012-09-23
而不是2012-09-16
必须有一种方法可以实现!必须以某种方式修改
Amend_Data
节点的相对路径...非常感谢您的帮助!PS:这与我上周五发布的问题can be found here有关。您可能会注意到该问题与本问题中列出的示例XML的结构差异。
最佳答案
这个:
(//my:Amend_Data)[last()]//my:Amend_Start_Date
应该可以。
不使用
last()
可以尝试://my:Amend_Info_Repeater[0=count(following-sibling::my:Amend_Info_Repeater)]/my:Amend_Data/my:Amend_Start_Date
关于xml - 返回重复节点集中的“最新”节点,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/12375053/