嗨,我想以百分比格式填充宽度中的maxbars变量的值,但由于某些原因,它没有取其值.你能帮忙吗?
示例:我想将其显示为宽度:10.9%格式
<xsl:for-each select="catalog/cd/price">
Current node:
<xsl:variable name="maxbars" select="."/>
<div style="width: 200px; height: 20px;">
<div style="width: maxbars%; height: 18px; background-color: red"></div>
</div>
<br/>
</xsl:for-each>
<catalog>
<cd>
<title>Empire Burlesque</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Hide your heart</title>
<artist>Bonnie Tyler</artist>
<country>UK</country>
<company>CBS Records</company>
<price>9.90</price>
<year>1988</year>
</cd>
Run Code Online (Sandbox Code Playgroud)
您必须表明您正在使用该maxbars变量.如果您在属性中使用它,则可以对xPath表达式使用XSL-T的大括号语法:
<div style="width: {$maxbars}%; height: 18px; background-color: red"></div>
Run Code Online (Sandbox Code Playgroud)
重要提示:大括号放在表达式周围,您使用$大括号内部.
如果要在属性之外插入变量(和其他xPath表达式),则必须使用以下<xsl:value-of>元素:
<span>Price: <xsl:value-of select="$maxbars"/></span>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23652 次 |
| 最近记录: |