FM 7.2 XSLT and unicode characters

John Root jroot at publisys.com
Sat May 6 12:43:22 PDT 2006


Hi Wim,

There is no if-else functionality in XSL. Instead, you use xsl:choose with a
series of nested xsl:when elements and an optional final xsl:otherwise.

i.e.: 

<xsl:choose>
    <xsl:when test="'foo'">Do something</xsl:when>
    <xsl:when test="'foobar'">Do something else</xsl:when>
    <xsl:otherwise>Perform some default action</xsl:otherwise>
</xsl:choose>

If I understand correctly what you're trying to do, you'd want your
intermediate transform to output ASCII or whatever encoding you require by
using an xsl:output element as a child of xsl:stylesheet:

<xsl:output type="xml" encoding="ASCII" />

You would use a standard copy type scenario but include a template for text
that calls the transform function. So your transform would look something
like this:


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

     <!-- Set encoding attribute per your choice -->
    <xsl:output method="xml" encoding="ASCII" />

    <xsl:template match="/">
        <xsl:apply-templates />
    </xsl:template>

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

    <xsl:template match="text()" priority="2">
        <xsl:choose>
            <xsl:when test="contains(., "UnicodeCharacter1)">
                <xsl:value-of select="translate(., "UnicodeCharacter1",
"ASCIICharacter1")
            </xsl:when>
            <xsl:when test="contains(., "UnicodeCharacter2)">
                <xsl:value-of select="translate(., "UnicodeCharacter2",
"ASCIICharacter2")
            </xsl:when>
            <xsl:otherwise><xsl:value-of select="."/>/xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>


Hope this helps,

John



     

On 5/5/06 2:43 AM, "Wim Hooghwinkel (Scriptware)" <wimh at scriptware.nl>
wrote:

> Hello all,
> 
> I am trying to create a XSLT template to transform uncode characters to ansii
> on import of XML in FM. This concerns the unicode characters for CE/EE
> languages that can not be read by FM.
> 
> As I don't have any experience with XSLT, could anyone point me in the right
> direction? Probably need a kind of if-else construction or variables to use
> the 'transate' function.
> 
> How does FM react when an XSLT refers to Javascript?
> 
> 
> Met vriendelijke groet / kind regards,
> 
> Wim Hooghwinkel wimh at scriptware.nl
> DTP and XML Management




More information about the framers mailing list