Xslt 如何通过@variable在xsl中添加样式属性
我有一个变量@expectedLength。我需要将其指定给样式属性Xslt 如何通过@variable在xsl中添加样式属性,xslt,Xslt,我有一个变量@expectedLength。我需要将其指定给样式属性 <xsl:if test="@expectedLength"> <xsl:attribute name="style"> <xsl:value-of select="'width:200px'"/> </xsl:attribute> &l
<xsl:if test="@expectedLength">
<xsl:attribute name="style">
<xsl:value-of select="'width:200px'"/>
</xsl:attribute>
</xsl:if>
我需要用@expectedLength的值替换200。如何使用该变量?您可以将代码段更改为
<xsl:if test="@expectedLength">
<xsl:attribute name="style">width: <xsl:value-of select="@expectedLength"/>;</xsl:attribute>
</xsl:if>
我更愿意和建议建立一个模板
<xsl:template match="@expectedLength">
<xsl:attribute name="style" select="concat('width: ', @expectedLength, ';')"/>
</xsl:template>
然后确保向上处理所有属性节点
<xsl:template match="@expectedLength">
<xsl:attribute name="style" select="concat('width: ', @expectedLength, ';')"/>
</xsl:template>