2017-09-24 8 views
1

안녕하세요 MarkLogic 9를 사용 중이고 FLWOR 문과 함께 XQuery를 사용하여 앱을 작성하려고합니다. 나는 http 서버를 설치했다. 포트 8031에서 정적 텍스트가있는 간단한 페이지를 테스트 해 보았습니다. 또한 쿼리 콘솔에서 FLWOR 문을 테스트했는데 제대로 작동합니다. 하지만 결합하면 작동하지 않습니다.MarkLogic 9의 FLWOR가 크롬에서 결과를 표시하지 않습니다.

나를 도울 수 있기를 바랍니다.

매니 감사

에릭

꽃 진술 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> 

HTTP 신청 페이지 enter image description here

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> 

답변

4

당신은 당신이 얻을 않은 결과에 대한 약간의 정확한 세부 사항을 언급하는 것을 잊었다하지만 코드를보고, 내가 추측하고있어, HTML 페이지는 않습니다 보여줄 것이지만 예상되는 행은 없습니다. 그것은 아마도 네임 스페이스 때문일 것입니다.

FLWOR 문을 리터럴 XHTML에 삽입했습니다. 일반적으로 괜찮습니다. 그러나 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!

+0

감사합니다. 이건 많이 도움이됩니다. –

+0

grtjn, 꽃 문으로 중첩을 처리하는 방법은 무엇입니까? –

+0

SO에 대한 예제가 있습니다. https://stackoverflow.com/q/11403946/918496 – grtjn