SXI Forum

A place to collect usefull tips, tricks and implementation strategies.

You are not logged in.

#1 22-11-2018 07:21:39

SeanR
Administrator
Registered: 20-11-2018
Posts: 148

Removing "Funny" Characters from XML

A numeric character reference (NCR) is a common markup construct used in SGML and SGML-derived markup languages such as HTML and XML. It consists of a short sequence of characters that, in turn, represents a single character. Since WebSgml, XML and HTML 4, the code points of the Universal Character Set (UCS) of Unicode are used. NCRs are typically used in order to represent characters that are not directly encodable in a particular document (for example, because they are international characters that don't fit in the 8-bit character set being used, or because they have special syntactic meaning in the language). When the document is interpreted by a markup-aware reader, each NCR is treated as if it were the character it represents.

Occasionally the components we integrate with may not accept or users may not want to see UCS characters. These can be removed/substituted using the Stylesheet (XSLT) Translate command. The following example shows how one can change an "En Dash" to a normal "Dash" (Minus Sign)

<xsl:template match="text()">
    <xsl:value-of select='translate(., "&#8211;", "&#045;")'/>
</xsl:template>

   
Thank You StephanB for this

Additional Information:
https://en.wikipedia.org/wiki/Numeric_c … _reference

Offline

#2 22-11-2018 08:32:48

SeanR
Administrator
Registered: 20-11-2018
Posts: 148

Re: Removing "Funny" Characters from XML

Here is my style sheet to translate the En Dash “–” to Dash (Minus Sign) “-”

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:strip-space elements="*"/>

    <xsl:output method="xml" encoding="utf-8" indent="yes"/>

    <xsl:template match="text()">
        <xsl:value-of select='translate(., "&#8211;", "&#045;")'/>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy>
            <xsl:copy-of select="@*"/>
            <xsl:apply-templates/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Offline

Board footer

Powered by FluxBB