0
我有以下XSL來填充複選框,但value
是空的。我需要的值是相應的dept
,region
和category
。請幫忙。複選框的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>
您可以編輯你的問題,以顯示您輸入XML的樣本嗎?謝謝。 –
@TimC我加了xml。提前致謝。 –