Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
| Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 20th, 2007, 06:00 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Using XSLT to generate PDF with Japanese text

Dear All,

I'm trying to generate PDF containing japanese text using XSLT templates. Input data for XSLT is coming from XML containing unicode characters as follows:

<?xml version="1.0" encoding="UTF-8"?>

<ReceiptData>
    <adminReceiptHeader>\u3053\u306e\u66f8\u985e\u3092 \u5927\u5207\u306b\u4fdd\u7ba1\u3057\u3066\u304f\u 3060\u3055\u3044\u3002</adminReceiptHeader>


....

</ReceiptData>

This XML is taken as input for the following XSLT snippet which outputs XSL-FO ; later converted to PDF uing FOP procesor. I'm using custom font 'msmincho.ttf' throughout XSLT body and titles.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:barcode="org.krysalis.barcode4j.xalan.Barcod eExt" extension-element-prefixes="barcode"
    version="1.1">

    <xsl:output method="xml" version="1.0" indent="yes"/>

    <xsl:template match="/">
        <fo:root>

            <fo:layout-master-set>
                <fo:simple-page-master master-name="POSReceipt" page-height="20cm" page-width="8cm"
                    margin-top="2cm" margin-bottom="0.5cm" margin-left="0.5cm" margin-right="0.5cm">
                    <fo:region-body margin-top="1.1cm" margin-bottom="0.5cm"/>
                    <fo:region-before extent="1cm"/>

                </fo:simple-page-master>
            </fo:layout-master-set>

            <fo:page-sequence master-reference="POSReceipt">
                <fo:flow flow-name="xsl-region-body">
                    <fo:block>
                        <xsl:call-template name="adminReceiptHeader"/>
                        <xsl:call-template name="adminReceiptBody"/>
                        <xsl:call-template name="adminReceiptFooter"/>
                    </fo:block>
                </fo:flow>
            </fo:page-sequence>

        </fo:root>
    </xsl:template>

    <xsl:template name="adminReceiptHeader">
        <xsl:if test="//header/text() != ''">
            <fo:block text-align="center" color="black"
                font-size="8pt" space-after=".2cm">
                <fo:inline font-weight="bold">
                  <xsl:value-of select="//adminReceiptHeader"/>
                </fo:inline>
            </fo:block>
        </xsl:if>

..............

</xsl:template>

</xsl:stylesheet>


My problem is that the output pdf does not contain Japanese characters as desired. It rather contains same unicode characters like \u3053\u306e as paased in input XML. Any help in this regard is greatly appreciated.














 
Old December 20th, 2007, 06:20 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

"\u3053" is the Java representation of Unicode characters. The XML representation is "#x3053;"

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 20th, 2007, 06:31 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


If I replace "\u3053" with "#x3053;" in my Input XML; output PDF now contains "#x3053;" instead of its Japanese equivalent.


 
Old December 20th, 2007, 06:37 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sorry, the forum software drops ampersands for some reason. That should have been "@#x3053;" where the @ character represents an ampersand.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old December 20th, 2007, 06:59 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default


I'm now getting sequence of # printed on PDF which does not seem to be Japanese character either. I have tried both the decimal (beginning with ampersand and hash) and hexadecimal equivalent (beginning with ampersand, hash and x) of the unicode character.




 
Old December 20th, 2007, 09:01 PM
Registered User
 
Join Date: Dec 2007
Location: , , .
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default



Hi, the problem is resolved now. My stylesheet was not picking up the MSMincho font correctly. I re-defined it, retained the '#x' change and its working now. Thanks very much for your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
how to generate random numbers in xslt anboss XSLT 3 July 23rd, 2008 09:10 AM
Using XSL to generate single pdf doc bhavanimachani XML 2 March 24th, 2008 11:57 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
generate id grouping using xslt meetnaveen4u XSLT 0 May 23rd, 2005 05:14 AM
How to generate an Error message from XSLT srini XSLT 2 December 16th, 2003 10:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.