[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] global language parameter


Subject: Re: [xsl] global language parameter
From: Charles Muller <cmuller-lst@xxxxxxxxxxxxxxx>
Date: Mon, 15 Feb 2010 12:06:35 +0900

Charles Muller wrote:

Wolfgang Laun wrote:

If this is NOT what you intend, please follow the suggestions of
others, and POST MORE INFO!

<xsl:template match="element()[@xml:lang]">
  <xsl:choose>
    <xsl:when test="@xml:lang='de'">
    <span style="font-family: 'URW Gothic L'">
      <xsl:copy-of select="."/>
    </span>
    </xsl:when>

This is exactly what I wanted to do. I will test this solution, as well as that offered by Ken Holman, shortly.


Both Wolfgang's and Ken's suggested templates work, thank you!

I realize, now, though, after testing this, that this is probably not the best way to achieve what I would like to do. This solution works fine for inline elements, such as <gloss xml:lang="ja">haiku</gloss> (let's say "haiku" was written in Japanese script), which would be transformed into something like <span style="font-family:Mincho">haiku</span>. In this case, <gloss> is essentially being replaced by <span>

But if I have a block element, let's say <p>:

The way I have been handling paragraphs for years is with this kind of structure:

<xsl:template match="p">
<xsl:choose>
<xsl:when test="@rend='indented'">
<p style="text-indent:12mm; margin-top: 0;
margin-bottom: 0; line-height:9mm;font-family: 'Times Ext Roman', 'Times New Roman'">
<xsl:apply-templates/>
</p>
</xsl:when>
<xsl:when test="@rend='plain'">
<p style="margin-left:0; margin-top:0; margin-bottom:0; text-indent:0mm; line-height:9mm;font-family: 'Times Ext Roman', 'Times New Roman'">
<xsl:apply-templates/>
</p>
</xsl:when>
...
... (etc.)
</xsl:choose>


This is fine as my standard way of writing in English.

But I also work with Japanese, Chinese, and Korean, and when I make paragraphs in those languages, I want to apply different fonts (and in some cases, different line heights, indents, etc., but for now, just focusing on fonts is OK).

Up to now, the way I have been handling this is by making separate attribute values for the same paragraph style in a different language. For example, an indented Chinese paragraph would be transformed with something like this:

<xsl:when test="@rend='indentedZH'">
<p style="text-indent:12mm; margin-top: 0;
margin-bottom: 0; line-height:9mm;font-family: 'MingLiU, Mincho. Simsum'">
<xsl:apply-templates/>
</p>
</xsl:when>


(all the values remain the same except for the font-family name)

And Korean:

<xsl:when test="@rend='indentedKO'">
<p style="text-indent:12mm; margin-top: 0;
margin-bottom: 0; line-height:9mm;font-family: 'BatangChe, Batang'">
<xsl:apply-templates/>
</p>
</xsl:when>


However, this begins to get unwieldy, since I basically need to replicate all of my paragraph formatting styles four times over, beyond the basic style I use for English. And so I recently thought that it would be better to take advantage of xml:lang for handling this, instead of creating an attribute value for each paragraph style in each language. This is what motivated my original query.

I realize that I could create a sub-tree under each attribute name, like

  <xsl:when test="@rend='indented'">
   <xsl:choose>
    <xsl:when test="lang=('en')">
      <p style="text-indent:12mm; margin-top: 0;
      margin-bottom: 0; line-height:9mm;font-family:
      'Times New Roman'">
      <xsl:apply-templates/>
      </p>
    </xsl:when>
    <xsl:when test="lang=('ja')">
      <p style="text-indent:12mm; margin-top: 0;
      margin-bottom: 0; line-height:9mm;font-family:
      Mincho">
      <xsl:apply-templates/>
      </p>
     </xsl:when>

    <xsl:when test="lang=('ko')">
      <p style="text-indent:12mm; margin-top: 0;
      margin-bottom: 0; line-height:9mm;font-family:
      Batang">
      <xsl:apply-templates/>
      </p>
     </xsl:when>
  </xsl:choose>
  </xsl:when>
 <xsl:when test="@rend='plain'">

(etc.)

I could do this, but it certainly seems unwieldy. Or is this the way people usually do it?

I can now use one of the templates kindly suggested by Ken and Wolfgang (which, based on my original query, implemented the <span> tag throughout). This is OK, but I wonder if it is appropriate or sensible to have this kind of situation throughout the generated document:

<span style="..."><p style="...">Text text text.</p></span>

Or, is there a more efficient way of making some kind of declaration for xml:lang that would work throughout the document, while inserting (concatenating?) the style values *inside* the already existent style values for <p>?

This is what I would like to check into.

I have both Jeni Tennison's and Michael Kay's thick books on XSL, but I have not been able to locate a discussion that deals with this kind of problem. Any advice would be appreciated.

Thank you,

Chuck



-------------------

A. Charles Muller

University of Tokyo
Graduate School of Humanities and Sociology, Faculty of Letters
Center for Evolving Humanities
Akamon kenkyE+ tE
#722
7-3-1 HongE
, BunkyE
-ku
Tokyo 113-0033, Japan

Web Site: Resources for East Asian Language and Thought
http://www.acmuller.net

<acmuller[at]jj.em-net.ne.jp>

Mobile Phone: 090-9310-1787


Current Thread
Keywords
xsl