首页 > 解决方案 > 在 HTML 属性中使用 XSL 参数值

问题描述

我有如下表格

        <form method="get"  action="change"  target="frame">
            <select name="fill" >
                <option>red</option>
                <option>green</option>
                <option>yellow</option>
                <option>pink</option>                                   
            </select>

        <input type="submit" value="darstellen"/>
        </form>

        <iframe name="frame">

        </iframe>

我希望表单将颜色发送到另一个包含矩形的 XSL 文件。到目前为止,将颜色传递给另一个 XSL 文件是可行的,但现在我想动态更改矩形的填充颜色,但使用传递的参数不起作用。

<map:match pattern="change">

<map:generate src="square.svg"/>

<map:transform src="recchange.xsl">

    <map:parameter name="use-request-parameters" value="true"/>

</map:transform>

<map:serialize type="html"/>

这是我的站点地图

<xsl:param name="fill"/>
<xsl:output method="html"/>

<xsl:template match="/">
<html>
    <body>

        <h2><xsl:value-of select="$fill"/></h2>
        <h1>testtest</h1>
        <svg>
              <rect width="300" height="100" style="fill:$fill;stroke-width:3;stroke:red">
              </rect>
        </svg>

这就是我到目前为止所尝试的。有人有建议吗?

标签: xmlxsltapache-cocoon

解决方案


您可以在此处使用属性值模板来评估$fill变量并直接在属性字符串中输出其值

 <rect width="300" height="100" style="fill:{$fill};stroke-width:3;stroke:red">

因此,花括号代表此处的属性值模板。


推荐阅读