English 中文(简体)
XQuery 无法按条款获得命令的验证
原标题:XQuery is not geting validate for Order by clause
  • 时间:2012-05-24 12:01:58
  •  标签:
  • xpath
  • xquery
for $i in cts:search(fn:collection()/article, $query)
    let $snippet :=  
        search:snippet( $i,.....)  

  order by if ($randomize) then ()   
     else if($sort-by = "ascending") then  
      xs:date($i/date_posted), cts:score($i)  
     else xs:date($i/date_posted) descending, cts:score($i) descending    

return
 element{"article"}
{ .....
  .....
  .....
}

Problem:
In above x-query statement, the order by clause has a condition that if($randomize) then () else the output provided will be in descending manner.

I have a requirement that according the sort-type provided by user I want to pull out the results in ascending or descending manner.

但对于上述书面代码, 我的x询问声明将无法验证 。

Thanks in Advance,
~Prashant

问题回答

不幸的是, XQuery 的排序规格是静态的, 甚至比 XSLT 的规格更是静态的。 如果您想要在向上或向下排序之间动态转换, 唯一的办法就是将排序键倒转。 数字很容易, 只需使用 - (KEY) 而不是 (KEY) 。 对于日期来说, 也并非太困难 — 从未来某个固定日期( 实际上, 任何日期) 中减去日期。 我无法想到任何方便的方式来进行字符串操作, 但幸运的是您似乎没有使用字符串 。





相关问题
VTD XML inner XPath Expressions

I have a xml file for example like this <root> <test> <bla>test1</bla> </test> <test> <bla>test2</bla> </test> <test> </test&...

C# XML adding/copying

With the following XML I am trying to copy and add to another XML but I haven t used the C# XML document objects before. So here is the XML <config> <configXML> <Connections&...

Filter SQL queries on the XML column using XPath/XQuery

I m having a table with one XML column. I d like to filter out the rows where a specific attribute in the XML match a string, essentially doing a WHERE or HAVING. The table looks something like this ...

Python XPath Result displaying only []

Hey I have just started to use Python recently and I want to use it with a bit of xPath, the thing is when I print the result of the query I only get [] and I don t know why =S import libxml2, ...

热门标签