Iris
Iris

Reputation: 1341

Manipulate the output of <xsl:apply-templates>

How do I string manipulation on the output of <xsl:apply-templates>?

I need to escape quotes etc as it's finally being passed to a JavaScript variable.

Upvotes: 0

Views: 2267

Answers (2)

Tomalak
Tomalak

Reputation: 338326

The nice and clean approach would be to change your XSLT so that it's output does not need any additional manipulation.

If your call to <xsl:apply-templates> produces a string that must be manipulated for some reason, you would need to capture it in a variable first:

<xsl:variable name="temp">
  <xsl:apply-templates />
</xsl:variable>

<xsl:variable name="temp-manipulated">
  <xsl:call-template name="do-some-string-mainpulation">
    <xsl:with-param name="string" select="$temp" />
  </xsl:call-template>
</xsl:variable>

<xsl:value-of select="$temp-manipulated" />

Alternatively, you can integrate the <xsl:apply-templates> into the <xsl:with-param>, wich would spare you one step:

<xsl:variable name="temp">
  <xsl:call-template name="do-some-string-mainpulation">
    <xsl:with-param name="string">
      <xsl:apply-templates />
    </xsl:with-param>
  </xsl:call-template>
</xsl:variable>

<xsl:value-of select="$temp" />

Upvotes: 2

Richard
Richard

Reputation: 109130

Capture in a variable, then manipulate the value to create the output:

<xsl:variable name='temp'>
  <xsl:apply-templates ...>
</xsl:variable>

<xsl:value-of select='expression involving $temp' />

Upvotes: 0

Related Questions