Loading ...
Sorry, an error occurred while loading the content.

3580Re: [XSL-FO] Getting special characters in FO

Expand Messages
  • Harm Kok
    Jun 5 4:56 AM
    • 0 Attachment
      Hi,

      I found the solution to my problem in the the book of Jeni Tennison. You
      can use this for formatters that don't support the font-family as FOP
      and Antennahouse.

      You can put the characters you want to replace in an XML file that looks
      like this:

      <root xmlns:fo="http://www.w3.org/1999/XSL/Format">
      <replace>
      <from>≤</from>
      <to><fo:inline font-family="Arial">≤</fo:inline></to>
      </replace><!-- smaller than or equal -->
      <replace>
      <from>≥</from>
      <to><fo:inline font-family="Arial">≥</fo:inline></to>
      </replace><!-- Larger than or equal -->
      </root>

      Than you can use the following stylesheet which I copied from Jeni her
      book. It replaces a string (in the "from" node) into a node (in the "to"
      node)

      <xsl:template match="text()">
      <xsl:call-template name="replace">
      <xsl:with-param name="string">
      <xsl:value-of select="."/>
      </xsl:with-param>
      </xsl:call-template>
      </xsl:template>

      <xsl:template name="replace">
      <xsl:param name="string" />
      <xsl:apply-templates
      select="document('character.xml')/root/replace[1]" mode="replace">
      <xsl:with-param name="string" select="$string"/>
      </xsl:apply-templates>
      </xsl:template>

      <xsl:template match="root/replace" mode="replace">
      <xsl:param name="string" />
      <xsl:variable name="next"
      select="following-sibling::replace[contains($string, from)][1]"/>
      <xsl:choose>
      <xsl:when test="contains($string, from)">
      <xsl:choose>
      <xsl:when test="$next">
      <xsl:apply-templates select="$next" mode="replace">
      <xsl:with-param name="string"
      select="substring-before($string, from)"/>
      </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
      <xsl:value-of select="substring-before($string, from)"/>
      </xsl:otherwise>
      </xsl:choose>
      <xsl:copy-of select="to/node()"/>
      <xsl:apply-templates select="." mode="replace">
      <xsl:with-param name="string"
      select="substring-after($string, from)"/>
      </xsl:apply-templates>
      </xsl:when>
      <xsl:when test="$next">
      <xsl:apply-templates select="$next" mode="replace">
      <xsl:with-param name="string" select="$string"/>
      </xsl:apply-templates>
      </xsl:when>
      <xsl:otherwise>
      <xsl:value-of select="$string"/>
      </xsl:otherwise>
      </xsl:choose>
      </xsl:template>

      Works like a charm.

      Regards,

      Harm
    • Show all 4 messages in this topic