Search

i've been trying to figure out how to output some javascript templates that have curly braces in my attributes, but it does not happen when output the innerHTML of a node. doing something like this (say $js-template is true()):

<a class="some-class">
    <xsl:attribute name="href">
        <xsl:choose>
            <xsl:when test="$js-template = true()">{{href}}</xsl:when>
            <xsl:otherwise><xsl:value-of select="$href" /></xsl:otherwise>
        </xsl:choose>
    </xsl:attribute>
    <xsl:choose>
        <xsl:when test="$js-template = true()">{{name}}</xsl:when>
        <xsl:otherwise><xsl:value-of select="$name" /></xsl:otherwise>
    </xsl:choose>
</a>

however, the output looks like this:

<a href="%7B%7Bhref%7D%7D">{{name}}</a>

instead of the desired output:

<a href="{{href}}">{{name}}</a>

I tried using the html entity equivalent for left/right curly braces, but the same output was happening.

has anyone experienced any fixes for this?

The only solution: output your anchor tag using a text element.

<xsl:choose>
    <xsl:when test="$js-template = true()">
         <xsl:text disable-output-escaping="yes">&lt;a class="some-class" href="{{href}}">{{name}}&lt;/a></xsl:text>
    </xsl:when>
    <xsl:otherwise>
        <a class="some-class" href="{$href}"><xsl:value-of select="$name" /></a>
    </xsl:otherwise>
</xsl:choose>

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details