将块转换为选择框

时间:2014-04-28 11:47:05

标签: xslt

请帮助转换块

<div id="category-list">
  <div class="category"><a href="/link-1">Sample Category</a></div>
  <div class="category"><a href="/link-2">Another Sample Category</a></div>
</div>

选择框(我将为自己工作的链接添加javascript)

<select>
    <option value="">Choose...</option>
    <option value="/link-1">Sample Category</option>
    <option value="/link-2">Another Sample Category</option>
</select>

1 个答案:

答案 0 :(得分:2)

使用

<xsl:template match="div[@id = 'category-list']">
  <select>
    <option value="">Choose...</option>
    <xsl:apply-templates/>
  </select>
</xsl:template>

<xsl:template match="div[@class = 'category']/a[@href]">
  <option value="{@href}"><xsl:value-of select="."/></option>
</xsl:template>