您的位置:首页 > Web前端 > HTML

XSL常见问题及解决(一)如何实现给html中标签li的id自动按序号命名

2017-07-13 17:58 531 查看
1、如果xml文件中已经有id,且该id是按照规律命名,我们只需要在xsl中读取该属性的值,然后为li赋值即可

xsl:

<xsl:template match="sec" mode="nav-item">
<li class="navItem">
<xsl:variable name="id">
<xsl:if test="@id">
<xsl:value-of select="@id"/>
</xsl:if>
</xsl:variable>
<a href="#{$id}">
<xsl:apply-templates select="title" mode="nav-item"/>
</a>
</li>
</xsl:template>


xml:

2、id可以用attribute元素去实现,元素的属性name为“id”;元素的值即为id名称

因为没有现成更的例子,暂时以a标签的href属性和img标签的src&alt属性为例,举一反三

xsl:

<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of
select="fig/alternatives/graphic[@specific-use='big']/@xlink:href"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of
select="fig/alternatives/graphic[@specific-use='big']/@xlink:href"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of
select="fig/alternatives/graphic[@specific-use='big']/@xlink:href"/>
</xsl:attribute>
</img>
</a>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: