如果在xPath / xQuery中有条件 [英] if condition in xPath/xQuery

查看:127
本文介绍了如果在xPath / xQuery中有条件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要连接xpath的结果,我使用 concat(normalize-space(。),'& #xA;')(感谢Dimitre Novatchev

To concatenate results from xpath, i'm using concat(normalize-space(.), '
') (Thanks to Dimitre Novatchev).

现在我想知道如何避免添加& #xA; 在最后一个元素之后......我正在考虑类似的事情: concat(normalize-space(。),if(if) XXXXX)然后'& #xA;'else'')但我无法弄清楚我必须使用什么条件。

Now i'm wondering how to avoid adding 
 after the last element... I'm thinking about something like: concat(normalize-space(.), if(XXXXX) then '
' else '') but I couldn't figure out what condition do I have to use.

例如,如果我使用 xpathExpression / concat(normalize-space(。),','),请求的值是(字符串)A& B& C& D,我期望的输出是 A,B,C,D 而不是 A,B,C,D, ....所以表达式可能变成: xpathExpression / concat(normalize-space(。),if(这是最后一个元素D)然后''else',')

For example, If I'm using xpathExpression/concat(normalize-space(.), ',') and the values requested are (strings) A & B & C & D, the output I'm expecting is A,B,C,D instead of A,B,C,D,.... so the expression may become: xpathExpression/concat(normalize-space(.), if(this is the last element D) then '' else ',')

推荐答案

如果你在XQuery或XPath 2.0中,你可以使用字符串连接函数,例如

If you're in XQuery or in XPath 2.0, you can use the string-join function, for example

string-join(//author, ', ')

会给你一个结果,如

Fleming, Rowling, Pullmann

如果你在XPath 1.0中,没有简单的等价物 - 但是你的问题并不清楚究竟是什么上下文是。

If you are in XPath 1.0, there's no easy equivalent - but it's not clear from your question exactly what the context is.

这篇关于如果在xPath / xQuery中有条件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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