XSL:使用复选框在XSLT中获取结果

时间:2017-09-25 18:27:12

标签: xml xslt

我在xsl(ver = 1.0)中生成以下表单(复选框)。我可以使用下拉菜单生成结果,其中结果中只包含一个选项。使用复选框,有多种方法可以在用户选中多个复选框时显示结果?例如,当用户检查部门1,部门2和区域1时,我需要计算项目并显示如下所示的行:

Search results for: department 1 & 2, region 1
Total: 3 items
department 1: 1 item
department 2: 2 items
region 1: 2 items

lines:
This is line 1 of description of item 1.
This is line 2 of description of item 1.
This is line 3 of description of item 1.
This is line 1 of description of item 2.
This is line 2 of description of item 2.
This is line 3 of description of item 2.
This is line 1 of description of item 3.
This is line 2 of description of item 3.
This is line 3 of description of item 3.

这是我的xsl生成的表单:

<form action method="post">
<input type="checkbox" name="dept" value="1">1
<input type="checkbox" name="dept" value="2">2
<input type="checkbox" name="region" value="region1">Region1
<input type="checkbox" name="region" value="region2">Region2
<input type="checkbox" name="category" value="category1">Category1
<input type="checkbox" name="category" value="category2">Category2
<input type="text">
<input type="submit" value="SUBMIT">
</form>

xml看起来像这样:

<?xml version="1.0" encoding="UTF-8"?>
<items>
    <item>
        <number>1</number>
        <dept>1</dept>
        <region>region1</region>
        <category>category1</category>
        <description>
            <pp>
                <line>
                    This is line 1 of description of item 1.
                </line>
                <line>
                    This is line 2 of description of item 1.
                </line>
                <line>
                    This is line 3 of description of item 1.
                </line>
            </pp>
        </description>
    </item>
    <item>
        <number>2</number>
        <dept>2</dept>
        <region>region1</region>
        <category>category2</category>
        <description>
            <pp>
                <line>
                    This is line 1 of description of item 2.
                </line>
                <line>
                    This is line 2 of description of item 2.
                </line>
                <line>
                    This is line 3 of description of item 2.
                </line>
            </pp>
        </description>
    </item>
    <item>
        <number>3</number>
        <dept>2</dept>
        <region>region2</region>
        <category>category2</category>
        <description>
            <pp>
                <line>
                    This is line 1 of description of item 3.
                </line>
                <line>
                    This is line 2 of description of item 3.
                </line>
                <line>
                    This is line 3 of description of item 3.
                </line>
            </pp>
        </description>
    </item>
</items>

1 个答案:

答案 0 :(得分:0)

传统上,如果您想在浏览器中处理用户事件(例如单击复选框)(而不是将结果发布回服务器),那么您可以编写一些Javascript事件处理程序。

现在还有另一种方法,即使用Saxon-JS编写XSLT中的所有事件处理,它是一个在浏览器中执行的XSLT 3.0处理器,并提供扩展以使其具有交互性。您可以编写类似这样的代码(未经测试):

package.json

这只是解决方案的草图,但如果你决定走这条路,我们很乐意帮助你充实它。

有关Saxon-JS的更多信息,请点击此处:

http://www.saxonica.com/saxon-js/index.xml