M
M
magary42017-06-07 17:32:43
XSL & XSLT
magary4, 2017-06-07 17:32:43

How to replace ampersand in template?

The replace-string function is taken
from here
, I call

<xsl:call-template name="replace-string">
                    <xsl:with-param name="text" select="@custom:src"/>
                    <xsl:with-param name="replace" select="'&amp;'" />
                    <xsl:with-param name="with" select="' '"/>
                </xsl:call-template>

but it replaces not the substring '&' but only one symbol &, i.e. I get ' amp;' Instead of a space
, what am I doing wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Fov, 2017-10-01
@Roman-Fov

what am I doing wrong?

Use translate. Down with weird features
<root>
      <foo>123&amp;456</foo>
</root>

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="/root/foo">
    <xsl:value-of select="translate(., '&amp;', ' ')"/>
  </xsl:template>
</xsl:stylesheet>

123 456

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question