2017-09-25 19 views
0

我在xsl(ver = 1.0)中生成以下表單(複選框)。我可以使用下拉菜單生成結果,其中結果中只包含一個選項。使用複選框,當用戶選中多個複選框時,是否可以顯示結果?例如,我需要計數的項目,並顯示這樣的行(下圖)時用戶檢查部門1,部門2和區域1:XSL:使用複選框在XSLT中獲取結果

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> 
+0

這就是JavaScript是什麼。 –

+0

@MatthewWhited你能提供任何例子嗎? –

回答

0

傳統上,如果你要處理用戶事件(如點擊複選框)在瀏覽器內(而不是發佈的結果返回給服務器)那麼你寫了一些Javascript事件處理程序。

現在還有另外一種方法來處理它,即使用Saxon-JS(它是一個在瀏覽器中執行的XSLT 3.0處理器)編寫所有事件處理,並提供擴展以使其交互。你會寫代碼是這樣的(未測試):

<xsl:template match="input[@type='checkbox']" mode="ixsl:click"> 
    <xsl:result-document href="#search-results-area"> 
    <xsl:variable name="checkedBoxes" 
     select="../input[@type='checkbox'][ixsl:get('checked')]"/> 
    <xsl:variable name="selectedItems" select="ixsl:source()//item[ 
     region = $checkedBoxes[@name='region']/@value 
     and number = $checkedBoxes[@name='number']/@value 
     and dept = $checkedBoxes[@name='dept']/@value]"/> 
    <p>Search results for ...</p> 
    <xsl:apply-templates select="$selectedItems"/> 
    </xsl:result-document> 
</xsl:template> 

<xsl:template match="item"> 
    <xsl:for-each select="description/p/line"> 
    <p><xsl:value-of select="."/></p> 
    </xsl:for-each> 
</xsl:template> 

這只是一個解決方案的草圖,但如果你決定要沿着這條路走下去,我們會很樂意幫助你割肉出來。在薩克森 - JS

的更多信息是在這裏:

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