Search code examples
xmlxsltapache-cocoon

Use XSL param value in HTML attribute


I have a form like the following

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

I want the form to send the color to another XSL file that contains a rectangle. So far the passing of the color to the other XSL file works but now I would like to dynamically change the fill color of the rectangle but using the passed parameter wont work.

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

This is my sitemap

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

And this is what I tried so far. Does anybody have advice?


Solution

  • You can use Attribute Value Templates here, to evaluate the $fill variable and output its value directly in the attribute string

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

    So, the curly braces represent the Attribute Value Template here.