XForms-动态分配实例资源

时间:2019-06-04 11:32:19

标签: xml xforms

我有一个xml文件集合,每个文件都与它的父母一起描述了一只杂种动物。

在raport.html页面上,我显示了一个包含所有动物的表格,每个动物都有一个单独的指向xForms站点的链接。

我的xForms文件中有

<?xml-stylesheet type="text/xsl" href="http://localhost:8080/exist/rest/db/apps/xsltforms/xsltforms.xsl"?><?xsltforms-options debug="no"?>
<html xmlns="http://www.w3.org/1999/xhtml" 
xmlns:ev="http://www.w3.org/2001/xml-events" 
xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:xf="http://www.w3.org/2002/xforms"
xmlns:z="zwierzeta" xmlns:a="anatomia">
    <head>
        <title>XForms</title>
        <xf:model>
            <xf:instance resource="data/liger.xml"/>
            <xf:submission id="update" resource="data/liger/xml" replace="none" method="put"/>
        </xf:model>
    </head>
    <body>
        <xf:input ref="/z:animals/z:animal/z:name">
            <xf:label>Name:</xf:label>
            <xf:hint>Nazwa</xf:hint>
        </xf:input>

           (...)

         <xf:submit submission="update">
            <xf:label>Save changes</xf:label>
         </xf:submit>

        <xf:trigger>
            <xf:label>Add parent</xf:label>
            <xf:action ev:event="DOMActivate">
                <xf:insert ref="//z:hybrid/z:animal[last()]" position="after" at="last()"/>
                <xf:setfocus control="nameInput"/>
            </xf:action>
        </xf:trigger>

        <xf:trigger>
            <xf:label>Delete parent</xf:label>
            <xf:delete ref="//z:hybrid/z:animal" at="index('parent')" ev:event="DOMActivate"/>
        </xf:trigger>

        <a href="raport.html">HomePage</a>

    </body>
</html>

只要我写文件名并且不要尝试更改它,哪个文件就可以很好地工作。

如何将不同的xml文件传递给xForms文件,以使模型使用每种动物的正确数据进行更新?

我尝试使用xQuery函数

declare function app:editFile($node as node(), $model as map(*)) {
    let $name := request:get-parameter('animal', '')
    let $a := (collection("/db/apps/projekt/data")/animals/animal[name=$name or hybrid//name=$name])[1]
    let $file := "data/" || $a/name/text() || ".xml"
    return 
        <xf:model>
            <xf:instance resource="{$file}"/>
            <xf:submission id="update" resource="{$file}" replace="none" method="put"/>
        </xf:model>
};

,并尝试使用带有class="app:editFile"的元素将结果呈现在xForms文件中,但不起作用。

我也尝试过

<xf:model>
<xf:instance resource="concat('data/',get-request-parameter('animal'),'.xml')"/>
<xf:submission id="update" resource="concat('data/',get-request-parameter('animal'),'.xml')" replace="none" method="put"/>
</xf:model>

但是这个也失败了。

0 个答案:

没有答案
相关问题