css - 使用 XSLT/XML 为 HTML 标签生成样式? (xsl :attribute-set)

标签 css xslt attributes stylesheet parent-child

好吧,这真是一个艰难的时刻……我在生成不同宽度的表格单元格时遇到了困难。我正在使用 XML/XSLT 输出我的 HTML,所以宽度基本上以 XML 格式存储:

<size>
<width1>5</width1>
<width2>4</width2>
<width3>7</width3>
</size>

使用 XSLT 的属性集,我应该有一个表格行和宽度分别为 5px、4px、7px 的单元格。然而,问题在于 attribute-set需要是 <xsl:stylesheet> 的 child 让它工作。我不能这样做:(原谅丢失的 px)

<tr>
    <td>
        <xsl:attribute-set name="style">
            <xsl:attribute name="width"><xsl:value-of select="size/width1"/></xsl:attribute>
        </xsl:attribute-set>
    </td>
    <td>
        <xsl:attribute-set name="style">
            <xsl:attribute name="width"><xsl:value-of select="size/width2"/></xsl:attribute>
        </xsl:attribute-set>
    </td>
    <td>
        <xsl:attribute-set name="style">
            <xsl:attribute name="width"><xsl:value-of select="size/width3"/></xsl:attribute>
        </xsl:attribute-set>
    </td>
</tr>

有什么方法可以使用 XML 数据生成 html 标签来设置它们的样式吗?

最佳答案

您需要在 <td> 中添加 xsl:attribute 而不是 xsl:attribute-set元素:

<xsl:template match="size">
    <tr>
        <td>
            <xsl:attribute name="width">
                <xsl:value-of select="./width1"/>
            </xsl:attribute>
        </td>

        <td>
            <xsl:attribute name="width">
                <xsl:value-of select="./width2"/>
            </xsl:attribute>
        </td>

        <td>
            <xsl:attribute name="width">
                <xsl:value-of select="./width3"/>
            </xsl:attribute>
        </td>
    </tr>
</xsl:template>

关于css - 使用 XSLT/XML 为 HTML 标签生成样式? (xsl :attribute-set),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5090190/

相关文章:

html - 关键帧动画 : slide then rotate

jquery - Nivo Slider - 仅显示静态图像

XSLT:如何检查多个节点是否适用于所有节点的某个值

php - 表单提交发送其他元素属性?

javascript - 尝试创建折叠/展开所有按钮

css - 多个相同的 RGBA 颜色不起作用

xslt - 使用 XSLT 进行展平 : I want to move one kind element one level

XSLT:分页问题的变体

javascript - Lightbox:图像描述的其他属性(而不是标题)

python - 将属性添加到 Python 字典中的现有对象