29a.ch by Jonas Wagner

Replacing Newlines and Quotes with XSLT

By

To replace newline and quotes with spaces just use translate(select, "
'", " ");

Example:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="text()">
    <xsl:value-of select='translate(., "&#xA;&apos;", "  ")' />
  </xsl:template>
  <xsl:template match="node">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
</xsl:stylesheet>