xsl-list
[Top] [All Lists]

Re: [xsl] global language parameter

2010-02-13 11:05:08
At 2010-02-14 01:41 +0900, Charles Muller wrote:
I'm taking my first stab at making a global parameter, through which I'd like to set font attributes for character sets of different languages. I'm using TEI-P5 with XSL 2, and I want my parameter to work with xml:lang.

In XSLT-speak a "global parameter" is a parameterized global variable. In your example code I see no references to any parameterized global variables.

It tried writing this way:

<xsl:template name="languageWrap">
   <xsl:param name="contents">
     <xsl:apply-templates/>
   </xsl:param>
   <xsl:choose>
     <xsl:when test="@xml:lang='sa'">
       <span style="font-family: 'Times Ext Roman'">
         <xsl:copy-of select="$contents"/>
       </span>
     </xsl:when>
    <xsl:when test="@xml:lang='zh'">
       <span style="font-family: Mincho,MingLiU, Batang, Simsun">
         <xsl:copy-of select="$contents"/>
       </span>
     </xsl:when>
    <xsl:when test="@xml:lang='ko'">
       <span style="font-family: Batang, BatangChe">
         <xsl:copy-of select="$contents"/>
       </span>
     </xsl:when>
     <xsl:otherwise>
       <xsl:copy-of select="$contents"/>
     </xsl:otherwise>
   </xsl:choose>
</xsl:template>


But nothing happens in the generated HTML--there are no <span> tags generated at all in the document. Any suggestions as to what I should be looking for here?

You don't give us your input stream with an example ... you just have a named template, so there isn't even a match= attribute to determine where you are testing this.

And I'm unclear why you are using a local variable for the processed contents ... though a smart XSLT processor would probably optimize it away.

Note, however, that the direct addressing of the xml:lang= attribute is not good form because of the language scope. This is expressly handled in XPath 1 and XPath 2 using the lang() function. In your code above I would have considered something along the lines of:

   <xsl:choose>
     <xsl:when test="lang('sa')">
       <span style="font-family: 'Times Ext Roman'">
         <xsl:apply-templates/>
       </span>
     </xsl:when>
    <xsl:when test="lang('zh')">
       <span style="font-family: Mincho,MingLiU, Batang, Simsun">
         <xsl:apply-templates/>
       </span>
     </xsl:when>
    <xsl:when test="lang('ko')">
       <span style="font-family: Batang, BatangChe">
         <xsl:apply-templates/>
       </span>
     </xsl:when>
     <xsl:otherwise>
         <xsl:apply-templates/>
     </xsl:otherwise>
   </xsl:choose>

The lang() function is particularly useful, because it will return true for lang('fr') when the closest ancestral xml:lang= declaration is xml:lang="fr" or xml:lang="fr-ca" or xml:lang="fr-anything at all here".

I hope this helps.

. . . . . . . . . . . . Ken


--
XSLT/XQuery/XPath training after http://XMLPrague.cz 2010-03-15/19
XSLT/XQuery/XPath training:   San Carlos, California 2010-04-26/30
Vote for your XML training:   http://www.CraneSoftwrights.com/s/i/
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--