如何使用XSL创建HTML属性? [英] How to use XSL to create HTML attributes?

查看:78
本文介绍了如何使用XSL创建HTML属性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么使用XML数据将HTML标签设计为非法?例如:

Why is using XML data to style HTML tags illegal? For example:

<li style="width:<xsl:value-of select="width"/>px"> 

为什么我不能这样做?是否还有其他方法?

Why can't I do this? Are there any alternative methods out there?

推荐答案


为什么我不能这样做?

Why can't I do this?

<li style="width:<xsl:value-of select="width"/>px">


由于XSL本身就是XML 。这是任何东西......但不是XML。

Because XSL is XML itself. And this is anything… but not XML.

你的意思是属性值模板

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

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

or the explicit form, for more complex expressions:

<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>

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

or dynamic attribute names (note that attribute value template in the name):

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

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

Additional note: Attributes must be created before all other child nodes. In other words, keep <xsl:attribute> at the top.

这篇关于如何使用XSL创建HTML属性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆