powered by simpleCommunicator - 2.0.49     © 2025 Programmizd 02
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / Возврат таблицы с помощью xquery по нажатию кнопки.
2 сообщений из 2, страница 1 из 1
Возврат таблицы с помощью xquery по нажатию кнопки.
    #39251695
fatum2002
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Приветствую всех.

Имею следующую ситуацию:
1. База eXist db
2. В ней хранится xquery, который формирует html страницу.
3. В этой html странице есть xquery функция, которая возвращает таблицу. Когда эта функция вызывается статически на странице, то таблица возвращается и всё работает.
4. Но конечный результат должен работать по-другому: есть еще несколько инпут контролов, которые появляются и в них можно ввести данные. Мне нужно параметры из этих инпут контролов передать функции и вызвать ее по нажатию кнопки. Вот с этим у меня проблемы.
5. Я пробовал скопировать функционал из функции в отдельный xquery скрипт, который тоже возвращает таблицу, и вызывать его через submission. Я думал, что результат выполнения этой xquery заменит содержимое xf:instance id="table". Но этого не происходит. Такое впечатление, что так я могу вернуть только строку текста в <xf:output ref="instance('table')/data/*> (тогда работает).
6. Если я изменяю replace="instance" на replace="all", то возвращается таблица в виде хтмл кода, но в таком случае вся предыдущая страница теряется.

Поэтому помогите разобраться, как вызвать функцию или отдельный квери, передать ему параметры из инпут контролов и отобразить возвращаемую таблицу на странице?

Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
132.
133.
134.
135.
136.
137.
138.
139.
140.
141.
142.
143.
144.
xquery version "3.0";

declare option exist:serialize "method=xhtml media-type=application/xhtml+xml indent=yes";

import module namespace xmldb="http://exist-db.org/xquery/xmldb";

declare variable $collection as xs:string := '/db/junitReports';

declare function local:table($collection as xs:string*, $interface as xs:string?, $date as xs:string?) as node() {
    <table border="1">
        <thead>
            <tr>
                <th>Inteface Name</th>
                <th>Test Date</th>
                <th>Test Result</th>
                <th>Report Link</th>
            </tr>
        </thead>
        <tbody>
        {   
            for $child in xmldb:get-child-resources($collection)
            let $doc := fn:doc(fn:concat($collection, '/', $child))
            where (fn:ends-with($child, '.xml')) 
                    and (($doc//*:interfaceName/text() eq $interface) or empty($interface))
                    and (($doc//*:reportDate/text() eq $date) or empty($date))
            order by $doc//*:reportDate/text() descending      
            return
            <tr>
                <td>
                    {$doc//*:interfaceName/text()}   
                </td>
                <td>
                    {$doc//*:reportDate/text()}  
                </td>
                <td>
                    {$doc//*:testResult/text()}  
                </td>
                <td>
                    <li>
                    <!--<a href="{document-uri(fn:doc(fn:concat($collection, '/', $child)))}">{$child}</a> -->
                    <a href="http://localhost:8080/exist/rest/db/junitReports/Report1.xml">  {$child}</a> 
                    </li>
                </td>
            </tr>
        }
        </tbody>
    </table>
};


<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:bf="http://betterform.sourceforge.net/xforms" xmlns:xf="http://www.w3.org/2002/xforms" bf:toaster-position="tl-down">
    <head>
        <title>IB interfaces regression testing report</title>
        <meta name="author" content="test"/>
        <meta name="author" content="test"/>
        <meta name="description" content="IB interfaces regression testing report"/>
        <link rel="stylesheet" type="text/css" href="styles/demo.css"/>
        
        <!-- INPUT CONTROLS -->
        <xf:model>
            <xf:instance id="default">
                <data xmlns="">
                    <CalendarDate constraint="true" readonly="false" required="false" relevant="true">
                        <value>{format-date(current-date(), '[Y]-[M01]-[D01]')}</value>
                    </CalendarDate>
                    <InterfaceName constraint="true" readonly="false" required="false" relevant="true">
                        <value>test</value>
                    </InterfaceName>
                    <trigger1 constraint="true" readonly="false" required="false" relevant="true">
                        <value>Button</value>
                    </trigger1>
                </data> 
            </xf:instance>
            
            <xf:instance id="table" xmlns="">
                <data/>
            </xf:instance>
            
            <xf:bind nodeset="CalendarDate">
                <xf:bind nodeset="value" type="date"/>
            </xf:bind>
            <xf:bind nodeset="InterfaceName">
                <xf:bind nodeset="value" type="string"/>
            </xf:bind>

            <xf:submission id="showTable"
                        method="get" 
                        action="/exist/rest/db/xquery/returnTable.xq"
                        replace="instance"
                        ref="instance('table')"
                        instance="table"
                        >
            </xf:submission>
        </xf:model>
    </head>
    
    <body class="soria" style="margin:30px;">
        <div class="Headline">IB test report</div>
        <div class="description">
            <p>You can restrict report output:</p>
            <p>1. By choosing particular date</p>
        </div>    
        <div class="Calendar">
            <xf:input id="CalendarDate" ref="CalendarDate/value" incremental="true">
                <xf:label></xf:label>
                <xf:hint>Date when test was run</xf:hint>
                <xf:help>message</xf:help>
                <xf:alert>Select a date</xf:alert>
            </xf:input>
        </div>  
        <p>2. By typing in particular interface name</p>
        <div class="InterfaceName">
            <xf:input id="InterfaceName" ref="InterfaceName/value" incremental="true">
                <xf:label></xf:label>
                <xf:hint>(S|R)xxxxxYYYZZZ</xf:hint>
                <xf:help>Enter interface name</xf:help>
                <xf:alert>Enter interface name</xf:alert>
            </xf:input>
        </div>
        <br/>
        <div>
            <xf:trigger id="trigger1" ref="trigger1/value" incremental="true">
                <xf:label>Filter output</xf:label>
                <xf:hint>a Hint for this control</xf:hint>
                <xf:help>help for trigger1</xf:help>
                <xf:action ev:event="DOMActivate">
                    <xf:send submission="showTable"/>
                </xf:action>
            </xf:trigger>
        </div>
        <div>
            <xf:output ref="instance('table')/data/*">
                <xf:label>Result:</xf:label>
            </xf:output>
        </div>
        
        
        <br/>
        <div>
            {local:table($collection,'RwillgEIFKFX',())}
         </div>
        <br/>
    </body>
</html>


Отдельный тестовый xquery для возрата таблицы по сабмит:

Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
xquery version "1.0";
declare namespace exist = "http://exist.sourceforge.net/NS/exist"; 
declare namespace system="http://exist-db.org/xquery/system";
declare namespace request="http://exist-db.org/xquery/request";
declare option exist:serialize "method=xml media-type=text/xml indent=yes";

let $test := test
return
<data>
    <table border="1">
        <thead>
            <tr>
                <th>Inteface Name</th>
                <th>Test Date</th>
                <th>Test Result</th>
                <th>Report Link</th>
            </tr>
        </thead>

    </table>
</data>
...
Рейтинг: 0 / 0
Возврат таблицы с помощью xquery по нажатию кнопки.
    #39252190
fatum2002
Скрыть профиль Поместить в игнор-лист Сообщения автора в теме
Участник
Я пошел по другому пути и снова столкнулся с препятствием:

Теперь я пытаюсь построить таблицу обращаясь к элементам instance('table') , которую возвращает дополнительная xquery.
Но сейчас мне возвращается только первая строка из набора. Я не знаю как проитерироваться правильно по instance('table')

1. Если вкладываю строки таблицы в
Код: xml
1.
<xf:repeat nodeset="instance('table')/results/result" id="row-repeat">

, то ничего не получаю.
2. Пытался написать через xquery и проитерироваться по интстанц через for, но в таком случае получаю ошибку
"Function instance() is not defined in module namespace: http://www.w3.org/2005/xpath-functions"
Как еще можно получить instance как nodeset, чтоб проитерироваться по нему через for ?

Код целиком:
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
48.
49.
50.
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
62.
63.
64.
65.
66.
67.
68.
69.
70.
71.
72.
73.
74.
75.
76.
77.
78.
79.
80.
81.
82.
83.
84.
85.
86.
87.
88.
89.
90.
91.
92.
93.
94.
95.
96.
97.
98.
99.
100.
101.
102.
103.
104.
105.
106.
107.
108.
109.
110.
111.
112.
113.
114.
115.
116.
117.
118.
119.
120.
121.
122.
123.
124.
125.
126.
127.
128.
129.
130.
131.
xquery version "3.0";

declare option exist:serialize "method=xhtml media-type=application/xhtml+xml indent=yes";

import module namespace xmldb="http://exist-db.org/xquery/xmldb";

declare variable $collection as xs:string := '/db/junitReports';

<html xmlns="http://www.w3.org/1999/xhtml" xmlns:ev="http://www.w3.org/2001/xml-events" xmlns:bf="http://betterform.sourceforge.net/xforms" xmlns:xf="http://www.w3.org/2002/xforms" bf:toaster-position="tl-down">
    <head>
        <title>IB interfaces regression testing report</title>
        <meta name="author" content="test"/>
        <meta name="author" content="test"/>
        <meta name="description" content="IB interfaces regression testing report"/>
        <link rel="stylesheet" type="text/css" href="styles/demo.css"/>
        
        <!-- INPUT CONTROLS -->
        <xf:model>
            <xf:instance id="default">
                <data xmlns="">
                    <CalendarDate constraint="true" readonly="false" required="false" relevant="true">
                        <value>{format-date(current-date(), '[Y]-[M01]-[D01]')}</value>
                    </CalendarDate>
                    <InterfaceName constraint="true" readonly="false" required="false" relevant="true">
                        <value>test</value>
                    </InterfaceName>
                    <trigger1 constraint="true" readonly="false" required="false" relevant="true">
                        <value>Button</value>
                    </trigger1>
                </data> 
            </xf:instance>
            
            <xf:instance id="table" xmlns="">
                <data>
                </data>
            </xf:instance>

            <xf:bind nodeset="CalendarDate">
                <xf:bind nodeset="value" type="date"/>
            </xf:bind>
            <xf:bind nodeset="InterfaceName">
                <xf:bind nodeset="value" type="string"/>
            </xf:bind>

            <xf:submission id="showTable"
                        method="get" 
                        action="/exist/rest/db/xquery/returnTable.xq"
                        replace="instance"
                        ref="instance('table')"
                        instance="table"
                        >
            </xf:submission>
        </xf:model>
    </head>
    
    <body class="soria" style="margin:30px;">
        <div class="Headline">IB test report</div>
        <div class="description">
            <p>You can restrict report output:</p>
            <p>1. By choosing particular date</p>
        </div>    
        <div class="Calendar">
            <xf:input id="CalendarDate" ref="CalendarDate/value" incremental="true">
                <xf:label></xf:label>
                <xf:hint>Date when test was run</xf:hint>
                <xf:help>message</xf:help>
                <xf:alert>Select a date</xf:alert>
            </xf:input>
        </div>  
        <p>2. By typing in particular interface name</p>
        <div class="InterfaceName">
            <xf:input id="InterfaceName" ref="InterfaceName/value" incremental="true">
                <xf:label></xf:label>
                <xf:hint>(S|R)xxxxxYYYZZZ</xf:hint>
                <xf:help>Enter interface name</xf:help>
                <xf:alert>Enter interface name</xf:alert>
            </xf:input>
        </div>
        <br/>
        <div>
            <xf:trigger id="trigger1" ref="trigger1/value" incremental="true">
                <xf:label>Filter output</xf:label>
                <xf:hint>a Hint for this control</xf:hint>
                <xf:help>help for trigger1</xf:help>
                <xf:action ev:event="DOMActivate">
                    <xf:send submission="showTable"/>
                </xf:action>
            </xf:trigger>
        </div>
        
        <xf:output ref="instance('table')/test/text()">
            <xf:label>Result:</xf:label>
        </xf:output>
        
        <div>
            <table border="1">
                <thead>
                    <tr>
                        <th>Inteface Name</th>
                        <th>Test Date</th>
                        <th>Test Result</th>
                        <th>Report Link</th>
                    </tr>
                </thead>
                <tbody>
                    <!--{   for $x in instance('table')
                        return -->
                            <tr>
                                <td>
                                    <xf:output ref="instance('table')//interfaceName/text()"></xf:output>   
                                </td>
                                <td>
                                    <xf:output ref="instance('table')//reportDate/text()"></xf:output> 
                                </td>
                                <td>
                                    <xf:output ref="instance('table')//testResult/text()"></xf:output>  
                                </td>
                                <td>
                                    <li>
                                        <xf:output ref="instance('table')//fileLink/text()"></xf:output>
                                    </li>
                                </td>
                            </tr>
                <!--}-->
                <!--<xf:repeat nodeset="instance('table')/results/result" id="row-repeat"> -->
                    <!--</xf:repeat> -->
                </tbody>
            </table>
        </div>
    </body>
</html>



returnTable.xq:
Код: html
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
15.
16.
17.
18.
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
33.
34.
35.
36.
37.
38.
xquery version "3.0";
declare namespace exist = "http://exist.sourceforge.net/NS/exist"; 
declare namespace system="http://exist-db.org/xquery/system";
declare namespace request="http://exist-db.org/xquery/request";
declare option exist:serialize "method=xml media-type=text/xml indent=yes";


declare variable $collection as xs:string := '/db/junitReports';
declare variable $interface as xs:string := '';
declare variable $date as xs:string := '';

let $theshow := "begin"
return 
    <results>
        {
            for $child in xmldb:get-child-resources($collection)
            let $doc := fn:doc(fn:concat($collection, '/', $child))
            where (fn:ends-with($child, '.xml')) 
                    and (($doc//*:interfaceName/text() eq $interface) or $interface eq '')
                    and (($doc//*:reportDate/text() eq $date) or $date eq '')
            order by $doc//*:reportDate/text() descending      
            return
                <result>
                    <interfaceName>
                        {$doc//*:interfaceName/text()}   
                    </interfaceName>
                    <reportDate>
                        {$doc//*:reportDate/text()}  
                    </reportDate>
                    <testResult>
                        {$doc//*:testResult/text()}  
                    </testResult>
                    <fileLink>
                        "http://localhost:8080/exist/rest/db/junitReports/Report1.xml" 
                    </fileLink>
                </result>
        }
    </results>


Эта квери возвращает такой набор:
Код: xml
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
<results>
  <result>
    <interfaceName>test1</interfaceName>
    <reportDate>2016-06-01</reportDate>
    <testResult>failure</testResult>
    <fileLink> "http://localhost:8080/exist/rest/db/junitReports/Report1.xml" </fileLink>
  </result>
  <result>
    <interfaceName>test2</interfaceName>
    <reportDate>2016-06-01</reportDate>
    <testResult>success</testResult>
    <fileLink> "http://localhost:8080/exist/rest/db/junitReports/Report1.xml" </fileLink>
  </result>
</results>
...
Рейтинг: 0 / 0
2 сообщений из 2, страница 1 из 1
Форумы / XML, XSL, XPath, XQuery [игнор отключен] [закрыт для гостей] / Возврат таблицы с помощью xquery по нажатию кнопки.
Целевая тема:
Создать новую тему:
Автор:
Закрыть
Цитировать
Найденые пользователи ...
Разблокировать пользователей ...
Читали форум (0):
Пользователи онлайн (0):
x
x
Закрыть


Просмотр
0 / 0
Close
Debug Console [Select Text]