2017-09-21 113 views
0

我有以下XSL來填充複選框,但value是空的。我需要的值是相應的dept,regioncategory。請幫忙。複選框的XSL設置值

這裏是xsl:

<xsl:key name="dept" match="/items/item/dept/text()" use="." /> 
<xsl:key name="region" match="/items/item/region/text()" use="." /> 
<xsl:key name="category" match="/items/item/category/text()" use="." /> 

<xsl:template match="/"> 
    <div class="w3-container w3-cell" style="background-color:#949494"> 
     <form> 
      <xsl:for-each select="/items/item/dept/text()[generate-id() 
       = generate-id(key('dept',.)[1])]"> 
       <input type="checkbox" name="dept" value="{dept}" />Department <xsl:value-of select="."/><br></br> 
      </xsl:for-each> 
      <br></br> 
      <xsl:for-each select="/items/item/region/text()[generate-id() 
       = generate-id(key('region',.)[1])]"> 
       <input type="checkbox" name="region" value="{region}" /> Region <xsl:value-of select="."/><br></br> 
      </xsl:for-each> 
      <br></br> 
      <xsl:for-each select="/items/item/category/text()[generate-id() 
       = generate-id(key('category',.)[1])]"> 
       <input type="checkbox" name="category" value="{category}" /> <xsl:value-of select="."/><br></br> 
      </xsl:for-each> 
      <br></br> 
      <input type="text" placeholder="Search Text.." /> 
      <br></br><br></br> 
      <input type="submit" value="Submit"/> 
      <br></br><br></br> 
     </form> 
</xsl:template> 

輸出應該是:

<input> type="checkbox" name="dept" value="dept1">Department 1 
<input> type="checkbox" name="dept" value="dept1">Department 2 
<input> type="checkbox" name="dept" value="region1">Region 1 
<input> type="checkbox" name="dept" value="region2">Region 2 
<input> type="checkbox" name="dept" value="category1">Category 1 
<input> type="checkbox" name="dept" value="category2">Category 2 

我的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

您可以編輯你的問題,以顯示您輸入XML的樣本嗎?謝謝。 –

+0

@TimC我加了xml。提前致謝。 –

回答

1

問題是與這條線(以及類似的對於地區和類別)

<input type="checkbox" name="dept" value="{dept}" /> 

此時您已經定位在dept元素上,所以此代碼正在查找名爲dept的子元素。

爲了得到當前dept的價值,而不是一個孩子,這樣做...

<input type="checkbox" name="dept" value="{.}" /> 
+0

啊,是的。謝謝。 –