Search code examples
xmlxsltselectsvgvalue-of

XSL - Do I need a Value-of?


<xsl:for-each select="/date/logs">

        <rect>

        <xsl:attribute name="fill">
        red
        </xsl:attribute>

......... This is a portion of my XSL transformation document. When I process it, the red comes out as just

&#10;&#9;&#9;red&#10;&#9;&#9;

Do I need a value-of select and a variable. I'm not that knowledgeable so sorry for my poor explanation.

Could Someone Help me Please, Thanks very much in advance.


Solution

  • You can use literal result elements including attribute values e.g.

    <xsl:for-each select="/date/logs">
      <rect fill="red"/>
    </xsl:for-each>
    

    If you want or need to populate an attribute value based on a value in your input doc use an attribute value template e.g.

    <xsl:for-each select="/date/logs">
      <rect fill="{@color}"/>
    </xsl:for-each>