开发者

Xquery node values where node starts with same text

How to create xquery to select node values where node name s开发者_如何学JAVAtarts with some text. for example document

<doc>
   <cpv1>Value1</cpv1>
   <cpv2>Value2</cpv2>
   <cpv3>Value3</cpv3>
   <zzz>Hello world!</zzz>
</doc>

It should get Value1,Value2,Value3


//doc/*[fn:starts-with(fn:local-name(), 'cpv')]/text()


So DocumentRequest nodes contains Alias nodes. I select all the Alias nodes which start with a prefix val.

<ArrayOfDocumentRequest>
    <DocumentRequest>
        <Alias>
            prefix1_OtherText
        </Alias>
    </DocumentRequest>
    <DocumentRequest>
        <Alias>
            prefix2_OtherText
        </Alias>
    </DocumentRequest>
</ArrayOfDocumentRequest>

<F_PREFIXLIST>
    <prefixes>
        <p>prefix1</p>
        <p>prefix2</p>
        <p>prefix3</p>
    </prefixes>
</F_PREFIXLIST>

for $i in /ArrayOfDocumentRequest
    for $p in $F_PREFIXLIST/prefixes/p                 
        return $i/DocumentRequest/Alias[fn:starts-with(text(), $p/text())]


Here is a xpath expression which given you Value1, Value2, Value3: //*[substring(text(), 1,5) ="Value"]/text()

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜