我有一个项目列表,我希望每个项目都成为一个网址.
列表:
<root>
<tags>
<tag>open source</tag>
<tag>open</tag>
<tag>advertisement</tag>
<tag>ad</tag>
</tags>
</root>
Run Code Online (Sandbox Code Playgroud)
XSLT:
<xsl:template match="*">
<div class="tags">
<xsl:for-each select="/post/tags/tag">
<a href="#">
<xsl:value-of select="//tag"/>
</a>
</xsl:for-each>
</div>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
输出:
<div class="tags">
<a href="#">open source</a>
<a href="#">open source</a>
<a href="#">open source</a>
<a href="#">open source</a>
</div>
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?
更正确的XSLT方法是添加"标记"模板并修改原始文件:
<xsl:template match="*">
<div class="tags">
<xsl:apply-templates select="tag" />
</div>
</xsl:template>
<xsl:template match="tag">
<a href="#">
<xsl:value-of select="."/>
</a>
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10292 次 |
| 最近记录: |