0

I use XSLT while convert Xml to html. I need to bind value to h4 tag to generate bookmark, but I get xslt compile error. How can I achive this ?

<xsl:for-each select="checklist">
            <table>
              <tbody>
                <tr>
                  <td>
                    <h4 id=<xsl:value-of select="@value"/>'>
                      <xsl:value-of select="@name"/>
                    </h4>
                  </td>
                </tr>
                <tr>
                  <td class="tbChecklist">
                  <xsl:copy-of select="summary"/>
                    </td>
                </tr>
              </tbody>
            </table>

</xsl:for-each>
Erkan
  • 1
  • 2

2 Answers2

1

You need to use Attribute Value Templates here

<h4 id="{@value}">
    <xsl:value-of select="@name"/>
</h4>

The curly braces indicate an expression to be evaluated, not output literally.

Note that you can also use xsl:attribute to do this

<h4>
    <xsl:attribute name="id">
        <xsl:value-of select="@value"/>
    </xsl:attribute>
    <xsl:value-of select="@name"/>
</h4>

But as you can see, AVTs are much preferable.

Tim C
  • 70,053
  • 14
  • 74
  • 93
0

That's because your XSLT file isn't well formatted. One possible solution is using xsl:attribute element:

<h4>
    <xsl:attribute name="id">
        <xsl:value-of select="@value"/>
    </xsl:attribute>
    <xsl:value-of select="@name"/>
</h4>

Though it's not much elegant. Another different solution is using a variable:

<xsl:variable name="id">
    <xsl:value-of select="@value"/>
</xsl:variable>

<xsl:variable name="value">
    <xsl:value-of select="@name"/>
</xsl:variable>

And use it where necessary:

<h4 id="{$id}"><xsl:value-of select="$value"/></h4>
BernatL
  • 72
  • 10