Max Li
Max Li

Reputation: 591

Can not use xsl:variable inside output text

My input XML is:

      <widget class="QPushButton" name="pushButton_4">
       <property name="whatsThis">
        <string extracomment="save()"/>
       </property>
       <property name="text">
        <string>保存</string>
       </property>
      </widget>

My xslt is:

  <xsl:variable name="ButtonAction"
                select="property[@name='whatsThis']/string/@extracomment"/>

  <xsl:template name="Button" match="widget[@class='QPushButton']">
    <button ng-click="$ButtonAction" class="btn btn-default">
      <xsl:value-of select="property[@name='text']/string" />
    </button>
  </xsl:template>

I want the output to be:

<button ng-click="save()" class="btn btn-default">保存</button>

However, what I actually get is:

<button ng-click="$ButtonAction" class="btn btn-default">保存</button>

How can I place a property text from the input xml into "" inside the output? I quickly tried xsl:text but it does not seem to work. I am using saxon-HE10. It seems that the processor does not treat " " as plain text for the output?

Upvotes: 0

Views: 45

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167426

In terms of XSLT you need an attribute value template, i.e. curly braces <button ng-click="{$ButtonAction}" class="btn btn-default"> to populate the attribute value with the result of evaluating the expression in curly braces.

Upvotes: 1

Related Questions