如何使用XSL创建HTML属性?

前端之家收集整理的这篇文章主要介绍了如何使用XSL创建HTML属性?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为什么要使用XML数据来标记HTML标签是非法的?例如:
<li style="width:<xsl:value-of select="width"/>px">

为什么我不能这样做?有什么替代方法吗?

解决方法

Why can’t I do this?

06000

因为XSL是XML本身。这是什么…但不是XML。

你的意思是Attribute Value Template

<li style="width:{width}px">

或显式表单,用于更复杂的表达式:

<li>
  <xsl:attribute name="style">
    <xsl:choose>
      <xsl:when test="some[condition = 'is met']">thisValue</xsl:when>
      <xsl:otherwise>thatValue</xsl:otherwise>
    </xsl:choose>
  </xsl:attribute>
</li>

或动态属性名称(请注意名称中的属性值模板):

<li>
  <xsl:attribute name="{$attrName}">someValue</xsl:attribute>
</li>

附加注意事项:必须在所有其他子节点之前创建属性。换句话说,请保持< xsl:attribute>在顶部。

原文链接:https://www.f2er.com/html/233009.html

猜你在找的HTML相关文章