如何在 XQuery 中打开字符串?
我有一个作为字符串输入的外部变量,我想对其进行 switch/case 操作。 我如何在 xquery 中做到这一点?
I have an external variable coming in as a string and I would like to do a switch/case on it. How do I do that in xquery?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需使用一系列 if 表达式:
使用类型开关会隐藏您真正在做什么。
其中哪种方法最有效取决于您所使用的 XQuery 处理器。 在理想的情况下,这应该只是一个品味问题,因为应该由优化器来选择合适的方法,但如果性能很重要,则值得对两个版本进行基准测试。 如果处理器优化了您的示例中的节点结构,并且没有将我的示例优化为专用交换机,我会感到非常惊讶。
Just use a series of if expressions:
Using a typeswitch is hiding what you are really doing.
Which of these methods is most efficient will depend on the XQuery processor you are using. In an ideal world it should only be a matter of taste, as it should be down to the optimizer to select the appropriate method, but if performance is important it is worth benchmarking both versions. I would be very surprised if a processor optimized the node construction out of your example, and didn't optimize my example to a specialized switch.
XQuery 没有用于切换除元素以外的任何内容的功能。
您要做的第一件事是将字符串转换为元素。
然后只需使用 typeswitch 进行普通切换:
请注意,这可能是 MarkLogic 唯一的解决方案。
XQuery doesn't have a function for switching on anything other than elements.
The first thing you do is convert your string to an element.
Then just use typeswitch to do a normal switch:
Please note, this may be a MarkLogic only solution.
从 XQuery 1.1 开始,使用开关:
http://www.w3.org/ TR/xquery-11/#id-switch
Starting with XQuery 1.1, use switch:
http://www.w3.org/TR/xquery-11/#id-switch
对于 Saxon,您可以使用如下内容:
https://rrusin。 blogspot.com/2010/01/xquery4j-in-action.html
For Saxon, you can use something like this:
https://rrusin.blogspot.com/2010/01/xquery4j-in-action.html
如果您的处理器支持 XQuery 1.1,那么您可以简单地执行以下操作:
If your processor supports XQuery 1.1, then you can simply do: