XPath:获取节点中最后一个兄弟节点的值 [英] XPath: Get value of last sibling in a node

查看:41
本文介绍了XPath:获取节点中最后一个兄弟节点的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个用于 MS InfoPath 的 XPath 表达式,以便检索节点中最后一个兄弟节点的值.(希望我能正确表达这个问题,因为我几乎没有使用过 XPath).

I am trying to create an XPath expression for use in MS InfoPath in order to retrieve the value of the last sibling in a node. (Hopefully I am phrasing this question correctly as I've barely ever used XPath).

我需要确定RepeaterGroup"节点内NamesEval"节点的最新实例.假设我会看看史蒂夫"是否参加了最新的活动;我将使用 contains(LatestEvent, "Steve") XPath 表达式检查这一点.如何让LatestEvent"仅加载最新的NamesEval"值?

I need to identify the most recent instance of the "NamesEval" node inside the "RepeaterGroup" node. Hypothetically I will be looking to see if "Steve" is attending the latest event; I will check for this using a contains(LatestEvent, "Steve") XPath expression. How do I get "LatestEvent" to load in only the most recent "NamesEval" value?

 <?xml version="1.0" encoding="UTF-8"?><?mso-infoPathSolution solutionVersion="1.0.0.2" productVersion="14.0.0" PIVersion="1.0.0.0" href="file:///C:\Documents%20and%20Settings\Chris\Local%20Settings\Application%20Data\Microsoft\InfoPath\Designer3\db543e141b8f4832\manifest.xsf" ?><?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?><my:myFields xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:InitialSection>
    <my:InitialField>1</my:InitialField>
    <my:InitialDate>2012-09-14</my:InitialDate>
</my:InitialSection>
<my:RepeaterSection>
    <my:RepeaterGroup>
        <my:RepeaterField>2</my:RepeaterField>
        <my:RepeaterDate>2012-09-15</my:RepeaterDate>
            <my:NamesGroup>
                <my:NamesRepeater>
                    <my:Name>Steve</my:Name>
                </my:NamesRepeater>
                <my:NamesRepeater>
                    <my:Name>Ashley</my:Name>
                </my:NamesRepeater>
                <my:NamesRepeater>
                    <my:Name>Josh</my:Name>
                </my:NamesRepeater>
            </my:NamesGroup>
        <my:NamesEval>Steve;Ashley;Josh;</my:NamesEval>
    </my:RepeaterGroup>
    <my:RepeaterGroup>
        <my:RepeaterField>3</my:RepeaterField>
        <my:RepeaterDate>2012-09-16</my:RepeaterDate>
        <my:NamesGroup>
            <my:NamesRepeater>
                <my:Name>Amanda</my:Name>
            </my:NamesRepeater>
            <my:NamesRepeater>
                <my:Name>Greg</my:Name>
            </my:NamesRepeater>
            <my:NamesRepeater>
                <my:Name>Steve</my:Name>
            </my:NamesRepeater>
            </my:NamesGroup>
        <my:NamesEval>Amanda;Greg;Steve;</my:NamesEval>
    </my:RepeaterGroup>
</my:RepeaterSection>

编辑 &答案

Choroba 回答了以下问题 - 这是解决方案://my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:NamesEval

Choroba answered the question below - here is the solution: //my:RepeaterGroup[0=count(following-sibling::my:RepeaterGroup)]//my:NamesEval

推荐答案

我不确定我是否理解您的问题.如果您试图验证最后的 NamesEval 是否包含字符串Steve",您可以使用以下 XPath 表达式:

I am not sure I understand your question. If you are trying to verify that the last NamesEval contains the string "Steve", you can use the following XPath expression:

contains((//my:NamesEval)[last()],'Steve')

这篇关于XPath:获取节点中最后一个兄弟节点的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆