Unicode (UTF-16) question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob Cox

    #1

    Unicode (UTF-16) question

    Hi (xsl novice here),

    I have a file called myResources.xml that contains some strings that
    will be localized.

    In myXSL.xsl file, I read the strings from here to output as html.
    myXSL.xsl is saved as UTF16.

    myResources.xml is currently saved as ASCII.

    Things work fine now.

    But...when I change myResources.xml and save it as UTF16 (and put the
    proper header <?xml version="1.0" encoding="UTF-16"?> at the top),
    then things don't work any more.

    The html that is generated is missing the strings that were supposed
    to be substituted from myResources.xml .

    It worked as ascii, but when I saved/switched myResources.xml to
    UTF16, the substitutions stopped working.

    myXSL.xsl is doing something like this:

    <stuff deleted>

    <xsl:variable name="translati onsFile" select="concat( $webRoot,
    '/xsl/','myResources. xml')"/>
    <xsl:variable name="translati ons"
    select="documen t($translations File)"/>
    <xsl:param name="isolang" select="'en'"/>

    <xsl:variable name="reportTit leText">
    <xsl:choose>
    <xsl:when test="count($tr anslations/LocalizedResour ces/resource[lang($isolang)]/displayText[@category='REPO RT_TITLE'])
    &gt; 0">
    <xsl:copy-of select="$transl ations/LocalizedResour ces/resource[lang($isolang)]/displayText[@category='REPO RT_TITLE']"/>
    </xsl:when>
    <xsl:otherwis e>
    <xsl:text>My Default Report String</xsl:text>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>


    --------------
    myResources.xml snippet below
    <resource xml:lang="en">
    <!-- Resources for viewing a report -->
    <displayText category="REPOR T_TITLE">Final Report</displayText>
    etc.
    -----------
    Thanks for any suggestions.
    Rob Cox
    rob_cox@dell.co m
  • Marrow

    #2
    Re: Unicode (UTF-16) question

    Hi Rob,

    It sounds as though when you are saving myResources.xml as UTF-16 it isn't
    actually being encoded properly as UTF-16. Have you checked that document
    loads and parses after saving it?

    Depending on your transformation engine - this might explain why the
    document() function is apparently bringing back nothing.
    (http://www.w3.org/TR/xslt#document - in particular "If there is an error in
    processing the fragment identifier, the XSLT processor may signal the error;
    if it does not signal the error, it must recover by returning an empty
    node-set."). In other words, if the document() function is failing to load
    the document because it is improperly encoded then it may be just returning
    an empty node-set - which might explain the behaviour you are seeing.

    Cheers
    Marrow
    http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
    http://www.topxml.com/Xselerator


    "Rob Cox" <rob_cox@dell.c om> wrote in message
    news:b0225442.0 410200748.4c1fd d45@posting.goo gle.com...[color=blue]
    > Hi (xsl novice here),
    >
    > I have a file called myResources.xml that contains some strings that
    > will be localized.
    >
    > In myXSL.xsl file, I read the strings from here to output as html.
    > myXSL.xsl is saved as UTF16.
    >
    > myResources.xml is currently saved as ASCII.
    >
    > Things work fine now.
    >
    > But...when I change myResources.xml and save it as UTF16 (and put the
    > proper header <?xml version="1.0" encoding="UTF-16"?> at the top),
    > then things don't work any more.
    >
    > The html that is generated is missing the strings that were supposed
    > to be substituted from myResources.xml .
    >
    > It worked as ascii, but when I saved/switched myResources.xml to
    > UTF16, the substitutions stopped working.
    >
    > myXSL.xsl is doing something like this:
    >
    > <stuff deleted>
    >
    > <xsl:variable name="translati onsFile" select="concat( $webRoot,
    > '/xsl/','myResources. xml')"/>
    > <xsl:variable name="translati ons"
    > select="documen t($translations File)"/>
    > <xsl:param name="isolang" select="'en'"/>
    >
    > <xsl:variable name="reportTit leText">
    > <xsl:choose>
    > <xsl:when[/color]
    test="count($tr anslations/LocalizedResour ces/resource[lang($isolang)]/displa
    yText[@category='REPO RT_TITLE'])[color=blue]
    > &gt; 0">
    > <xsl:copy-of[/color]
    select="$transl ations/LocalizedResour ces/resource[lang($isolang)]/displayTex
    t[@category='REPO RT_TITLE']"/>[color=blue]
    > </xsl:when>
    > <xsl:otherwis e>
    > <xsl:text>My Default Report String</xsl:text>
    > </xsl:otherwise>
    > </xsl:choose>
    > </xsl:variable>
    >
    >
    > --------------
    > myResources.xml snippet below
    > <resource xml:lang="en">
    > <!-- Resources for viewing a report -->
    > <displayText category="REPOR T_TITLE">Final Report</displayText>
    > etc.
    > -----------
    > Thanks for any suggestions.
    > Rob Cox
    > rob_cox@dell.co m[/color]


    Comment

    • Andreas Prilop

      #3
      Re: Unicode (UTF-16) question

      On 20 Oct 2004, Rob Cox wrote:
      [color=blue]
      > I have a file called myResources.xml that contains some strings that
      > will be localized.
      >
      > In myXSL.xsl file, I read the strings from here to output as html.
      > myXSL.xsl is saved as UTF16.[/color]

      Use UTF-8 instead of UTF-16 - especially when your final goal is HTML.
      UTF-16 isn't currently a good idea for HTML.


      --
      Top-posting.
      What's the most irritating thing on Usenet?

      Comment

      • Alan J. Flavell

        #4
        Re: Unicode (UTF-16) question

        On Wed, 20 Oct 2004, Andreas Prilop wrote:
        [color=blue]
        > On 20 Oct 2004, Rob Cox wrote:
        >[color=green]
        > > I have a file called myResources.xml that contains some strings that
        > > will be localized.
        > >
        > > In myXSL.xsl file, I read the strings from here to output as html.
        > > myXSL.xsl is saved as UTF16.[/color]
        >
        > Use UTF-8 instead of UTF-16 - especially when your final goal is HTML.
        > UTF-16 isn't currently a good idea for HTML.[/color]

        As far as what is served-out to the web is concerned, I would agree
        with you...

        But to some extent it's the hon Usenaut's own private affair how they
        choose to store their data internally, if they have a good way to
        recode it into an appropriate form for serving out to the web.
        [color=blue]
        > http://ppewww.ph.gla.ac.uk/~flavell/...checklist.html[/color]

        Well, that page aims specifically at the use of HTML served as
        text/html in a WWW context for browsing with HTML-ish browsers.

        There's a brief note about XHTML/1.0 served out under Appendix C,
        but I don't go any more-deeply into XML issues. It'd be interesting,
        seeing that we're on an XML group, if XML practitioners would care
        to review it and see how it matches their own views of the
        practicalities.

        Comment

        Working...