MarkLogic 9中的FLWOR在chrome中不显示结果
问题描述:
您好,我正在使用MarkLogic 9,并尝试使用XQuery和FLWOR语句一起构建一个应用程序。我设置了http服务器。我用8031端口上的静态文本测试了一个简单的页面,它工作正常。我还在查询控制台中测试了一个 FLWOR语句,该语句也正常工作。但是当我结合它时,它不起作用。MarkLogic 9中的FLWOR在chrome中不显示结果
我希望你能帮助我。
曼尼感谢
埃里克
FLOWER STATEMENT ML 9.0
for $i in /scope/item
let $sscc := $i/transaction/sscc/text()
return <tr><td>{$sscc}</td></tr>
TEST.XQY
xquery version "1.0-ml";
xdmp:set-response-content-type("text/html; charset=utf-8"),
'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">',
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Find my orders</title>
</head>
<body>
<table>
<tr><th>SSCC</th></tr>
{
for $i in /scope/item
let $sscc := $i/transaction/sscc/text()
return <tr><td>{$sscc}</td></tr>
}
</table>
</body>
</html>
XML源文件
<scope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<item>
<transaction>
<type>CI</type>
<sscc>00000379471900000025</sscc>
<location>4260210630688</location>
<device>VISTALINK.004</device>
<date>2017-04-25</date>
<time>02:15:33</time>
<gmtOffset>+02:00</gmtOffset>
<actorId>155081</actorId>
</transaction>
<order>
<orderNumber>3794719</orderNumber>
</order>
<load>
<rti>
<ean>8714548186004</ean>
<grai>8003087145481860040019877322</grai>
<column>2</column>
<size>
<width>1900</width>
<height>95</height>
<depth>0</depth>
</size>
<position>
<x>2062,48707520218</x>
<y>2015,24337520512</y>
<z>0</z>
</position>
</rti>
<rti>
<ean>8714548106002</ean>
<grai>8003087145481060020016434653</grai>
<column>0</column>
<size>
<width>1900</width>
<height>95</height>
<depth>0</depth>
</size>
<position/>
</rti>
<rti>
<ean>8714548186004</ean>
<grai>8003087145481860040012803719</grai>
<column>2</column>
<size>
<width>1900</width>
<height>95</height>
<depth>0</depth>
</size>
<position>
<x>2064,20629390666</x>
<y>2124,57539157396</y>
<z>0</z>
</position>
</rti>
<rti>...</rti>
<rti>...</rti>
<rti>...</rti>
<rti>...</rti>
<rti>...</rti>
</load>
</item>
</scope>
答
你忘了提及一下,结果你没得到一些具体的细节,但是看着你的代码,我猜,你的HTML页显示,但没有预期的行。这可能是由于命名空间。
您已经在文字XHTML中嵌入了FLWOR语句。这通常很好,但是由于你的XHTML携带了默认的命名空间声明,所以包含在同一个XML中的XPath表达式将被解释为具有相同的命名空间声明。这意味着在您的情况下,像/scope/item
这样的XPath表达式实际上被解释为/xhtml:scope/xhtml:item
。
最简单的方法是预先抓取项目,和/或使用通配符前缀。也许是这样的:
let $items := fn:collection()/scope/item
return
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Find my orders</title>
</head>
<body>
<table>
<tr><th>SSCC</th></tr>
{
for $i in $items
let $sscc := $i/*:transaction/*:sscc/text()
return <tr><td>{$sscc}</td></tr>
}
</table>
</body>
</html>
HTH!
谢谢,这可以帮助我很多 –
grtjn,你是如何处理嵌套与花的声明? –
SO上有例子:https://stackoverflow.com/q/11403946/918496 – grtjn