[Momonga-devel.ja:02359] Re: docbook-style-xsl person-name template for ja


しげゆき です.

> わかりました。
> zh や ko を真似して person-name の template に
> first-last と書いてみたら直りました。
> その際に使った patch を添付します。
> 
> person-name 以外の部分については、
> もともとあった ja.xml を反映すべく努力しましたが
> わからなくて適当にごまかした箇所が多々あります。
> ので、どなたか確認していただければ幸いです。
> 

パッチ見てみました.

パッチで,

   <l:gentext key="sect1" text="節"/>
   <l:gentext key="sect2" text="節"/>
   <l:gentext key="sect3" text="節"/>
   <l:gentext key="sect4" text="節"/>
   <l:gentext key="sect5" text="節"/>
   <l:gentext key="Section" text="節"/>
   <l:gentext key="section" text="節"/>

など *sect* のセクション部分を 『項』 から 『節』 に変更してると見たんです
が,下の方の name="*sect*" な部分も同じく 『節』 に統一した方が良さげ
かなと思いました.

# 私はdocbook-style-xslも良く解ってないんで変な事のたまってるかも…….

tamoさんのパッチが当たった ja.xmlを更に変更したモノ (ja_patched.xml) 
と,数値文字参照では何が何やら解りにくいので ent -> char 変換してある
モノ (ja_patched_noent.xml これはUTF-8で書き出してます) ,それと,相互
変換するのに作ったその夜限り(謎)の使い捨てツール(attr_char2nument,
attr_nument2char)を添付しときます.

それから,前のバージョンで当てられてた htmlattr.patch と nosvg.patch
も作りなおしてみましたので,それも添付しときます.
確認お願いできますか?

ツールの,

attr_nument2char は 属性値を数値文字参照から文字へ
attr_char2nument は 属性値の 0x80以上の文字を数値文字参照へ

それぞれ変換します.出力はSTDOUTです.
要 php-cli です.chmod +x して使ってくださいまし.
コードがカコワルイのは言いっこ無しということで.
バグがあるかも知れないので,その時はごめんなさい.

# つーか,tamoさん,このパッチ作った時,何使って書きました?
# 簡単に属性値だけ char -> ent, ent -> charするツールって既にあります?


-- 

やましたしげゆき <shige@xxxxxxxxxxxxx>
        http://sickhack.homelinux.org/
「肩書きぃ? んなもなぁねえよ! けっ」

Attachment: ja_patched.xml
Description: application/xml

Attachment: ja_patched_noent.xml
Description: application/xml

#!/usr/bin/php-cli
<?php

$buf = "";

if ($argc == 2 && file_exists($argv[1])) {
    $fp = false;
    $fp = fopen($argv[1],"r") or exit(sprintf("cannot open file \"%s\"\n",$argv[1]));
    while(!feof($fp)) {
        $buf .= fgets($fp,4096);
    }
    fclose($fp);
    $buf = attr_char2nument($buf);
    fwrite(STDOUT,mb_convert_encoding($buf,"UTF-8",mb_detect_encoding($buf)));
}
else {
    exit(sprintf("Usage: %s filename\nOutput is STDOUT\n",basename($argv[0])));
}


function attr_char2nument($str) {
    $buf = "";
    $str = preg_replace("/\x0d\x0a|[\x0d\x0a]/","\n",$str);
    $str = mb_convert_encoding($str,"UTF-8",mb_detect_encoding($str));
    $tmp = array();
    preg_match_all("'((</?)([-\!\?a-zA-Z0-9:]+)([^/\?>]*)([/\?]*>\s*))?(.*?)'s",$str,$tmp,PREG_SET_ORDER);
    for($i = 0; $i < count($tmp); $i++) {
        $buf .= $tmp[$i][2]; // tagstart '<'
        $buf .= $tmp[$i][3]; // element name
        $attr = array();
        preg_match_all("/( [a-zA-Z0-9:]+=\")([^\"]+)(\")|(.*)/",$tmp[$i][4],$attr,PREG_SET_ORDER);
        $attrs = "";
        for ($j = 0; $j < count($attr);$j++) {
            $attrs .= $attr[$j][1];
            $attrs .= c2e($attr[$j][2]);
            $attrs .= $attr[$j][3];
            $attrs .= $attr[$j][4];
        }
        $buf .= $attrs;      // encoded attributes
        $buf .= $tmp[$i][5]; // tagend '/>'
        $buf .= $tmp[$i][6]; // not element
    }
    return $buf;
}

function c2e($str) {
    $buf = "";
    $map =array();
    $map = array(0x00080,0xfffff,0,0xfffff);
    $buf = mb_encode_numericentity($str,$map,'UTF-8');
    return $buf;
}


?>
#!/usr/bin/php-cli
<?php

$buf = "";

if ($argc == 2 && file_exists($argv[1])) {
    $fp = false;
    $fp = fopen($argv[1],"r") or exit(sprintf("cannot open file \"%s\"\n",$argv[1]));
        while(!feof($fp)) {
        $buf .= fgets($fp,4096);
    }
    fclose($fp);
    $buf = attr_nument2char($buf);
    fwrite(STDOUT,mb_convert_encoding($buf,"UTF-8",mb_detect_encoding($buf)));
}
else {
    exit(sprintf("Usage: %s filename\nOutput is STDOUT\n",basename($argv[0])));
}


function attr_nument2char($str) {
    $buf = "";
    $str = preg_replace("/\x0d\x0a|[\x0d\x0a]/","\n",$str);
    $str = mb_convert_encoding($str,"UTF-8",mb_detect_encoding($str));
    $tmp = array();
    preg_match_all("'((</?)([-\!\?a-zA-Z0-9:]+)([^/\?>]*)([/\?]*>\s*))?(.*?)'s",$str,$tmp,PREG_SET_ORDER);
    for($i = 0; $i < count($tmp); $i++) {
        $buf .= $tmp[$i][2]; // tagstart
        $buf .= $tmp[$i][3]; // element name
        $attr = array();
        preg_match_all("/( [a-zA-Z0-9:]+=\")([^\"]+)(\")|(.*)/",$tmp[$i][4],$attr,PREG_SET_ORDER);
        $attrs = "";
        for ($j = 0; $j < count($attr);$j++) {
            $attrs .= $attr[$j][1];
            $attrs .= e2c($attr[$j][2]);
            $attrs .= $attr[$j][3];
            $attrs .= $attr[$j][4];
        }
        $buf .= $attrs;      // decoded attributes
        $buf .= $tmp[$i][5]; // tagend
        $buf .= $tmp[$i][6]; // not element
    }
    return $buf;
}

function e2c($str) {
    $buf = "";
    $map =array();
    $map = array(0x00080,0xfffff,0,0xfffff);
    $buf = mb_decode_numericentity($str,$map,'UTF-8');
    return $buf;
}

?>
diff -uNbr docbook-xsl-1.62.4/html/chunk-common.xsl docbook-xsl-1.62.4.htmlattr/html/chunk-common.xsl
--- docbook-xsl-1.62.4/html/chunk-common.xsl	2003-09-29 05:21:31.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/html/chunk-common.xsl	2003-11-22 07:34:10.000000000 +0900
@@ -929,6 +929,7 @@
   </xsl:param>
 
   <html>
+    <xsl:call-template name="html.attributes"/>
     <xsl:call-template name="html.head">
       <xsl:with-param name="prev" select="$prev"/>
       <xsl:with-param name="next" select="$next"/>
diff -uNbr docbook-xsl-1.62.4/html/docbook.xsl docbook-xsl-1.62.4.htmlattr/html/docbook.xsl
--- docbook-xsl-1.62.4/html/docbook.xsl	2003-08-28 08:58:14.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/html/docbook.xsl	2003-11-22 07:35:39.000000000 +0900
@@ -101,6 +101,9 @@
   <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template name="html.attributes">
+</xsl:template>
+
 <xsl:template name="body.attributes">
   <xsl:attribute name="bgcolor">white</xsl:attribute>
   <xsl:attribute name="text">black</xsl:attribute>
@@ -327,6 +330,7 @@
   <xsl:call-template name="root.messages"/>
 
   <html>
+    <xsl:call-template name="html.attributes"/>
     <head>
       <xsl:call-template name="system.head.content">
         <xsl:with-param name="node" select="$doc"/>
diff -uNbr docbook-xsl-1.62.4/html/titlepage.xsl docbook-xsl-1.62.4.htmlattr/html/titlepage.xsl
--- docbook-xsl-1.62.4/html/titlepage.xsl	2003-08-10 02:56:46.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/html/titlepage.xsl	2003-11-22 07:36:15.000000000 +0900
@@ -468,6 +468,7 @@
         <xsl:with-param name="quiet" select="$chunk.quietly"/>
         <xsl:with-param name="content">
           <html>
+            <xsl:call-template name="html.attributes"/>
             <head>
               <xsl:call-template name="system.head.content"/>
               <xsl:call-template name="head.content"/>
diff -uNbr docbook-xsl-1.62.4/xhtml/chunk-common.xsl docbook-xsl-1.62.4.htmlattr/xhtml/chunk-common.xsl
--- docbook-xsl-1.62.4/xhtml/chunk-common.xsl	2003-09-29 05:22:35.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/xhtml/chunk-common.xsl	2003-11-22 07:38:40.000000000 +0900
@@ -878,6 +878,7 @@
   </xsl:param>
 
   <html>
+    <xsl:call-template name="html.attributes"/>
     <xsl:call-template name="html.head">
       <xsl:with-param name="prev" select="$prev"/>
       <xsl:with-param name="next" select="$next"/>
diff -uNbr docbook-xsl-1.62.4/xhtml/docbook.xsl docbook-xsl-1.62.4.htmlattr/xhtml/docbook.xsl
--- docbook-xsl-1.62.4/xhtml/docbook.xsl	2003-08-30 00:00:48.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/xhtml/docbook.xsl	2003-11-22 07:38:19.000000000 +0900
@@ -98,6 +98,9 @@
   <xsl:value-of select="."/>
 </xsl:template>
 
+<xsl:template name="html.attributes">
+</xsl:template>
+
 <xsl:template name="body.attributes">
 <!-- no apply-templates; make it empty -->
 </xsl:template>
@@ -296,6 +299,7 @@
   <xsl:call-template name="root.messages"/>
 
   <html>
+    <xsl:call-template name="html.attributes"/>
     <head>
       <xsl:call-template name="system.head.content">
         <xsl:with-param name="node" select="$doc"/>
diff -uNbr docbook-xsl-1.62.4/xhtml/titlepage.xsl docbook-xsl-1.62.4.htmlattr/xhtml/titlepage.xsl
--- docbook-xsl-1.62.4/xhtml/titlepage.xsl	2003-08-19 05:23:11.000000000 +0900
+++ docbook-xsl-1.62.4.htmlattr/xhtml/titlepage.xsl	2003-11-22 07:39:27.000000000 +0900
@@ -453,6 +453,7 @@
         <xsl:with-param name="quiet" select="$chunk.quietly"/>
         <xsl:with-param name="content">
           <html>
+            <xsl:call-template name="html.attributes"/>
             <head>
               <xsl:call-template name="system.head.content"/>
               <xsl:call-template name="head.content"/>
diff -uNbr docbook-xsl-1.62.4/common/common.xsl docbook-xsl-1.62.4.nosvg/common/common.xsl
--- docbook-xsl-1.62.4/common/common.xsl	2003-05-08 08:27:34.000000000 +0900
+++ docbook-xsl-1.62.4.nosvg/common/common.xsl	2003-11-22 07:44:43.000000000 +0900
@@ -1038,9 +1038,6 @@
   </xsl:variable>
 
   <xsl:choose>
-    <xsl:when test="$use.svg = 0 and $format = 'SVG'">0</xsl:when>
-    <xsl:when xmlns:svg="http://www.w3.org/2000/svg";
-              test="$use.svg != 0 and $object/svg:*">1</xsl:when>
     <xsl:when test="$graphic.format = '1'">1</xsl:when>
     <xsl:when test="$graphic.ext = '1'">1</xsl:when>
     <xsl:otherwise>0</xsl:otherwise>
@@ -1603,4 +1600,3 @@
 </xsl:template>
 
 </xsl:stylesheet>
-
diff -uNbr docbook-xsl-1.62.4/html/graphics.xsl docbook-xsl-1.62.4.nosvg/html/graphics.xsl
--- docbook-xsl-1.62.4/html/graphics.xsl	2003-08-10 02:56:45.000000000 +0900
+++ docbook-xsl-1.62.4.nosvg/html/graphics.xsl	2003-11-22 07:46:37.000000000 +0900
@@ -873,15 +873,6 @@
 </xsl:template>
 
 <xsl:template match="imageobject">
-  <xsl:choose>
-    <xsl:when xmlns:svg="http://www.w3.org/2000/svg";
-              test="svg:*">
-      <xsl:apply-templates/>
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:apply-templates select="imagedata"/>
-    </xsl:otherwise>
-  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="imagedata">
@@ -1134,13 +1125,5 @@
 </xsl:template>
 
 <!-- ==================================================================== -->
-<!-- "Support" for SVG -->
-
-<xsl:template match="svg:*" xmlns:svg="http://www.w3.org/2000/svg";>
-  <xsl:copy>
-    <xsl:copy-of select="@*"/>
-    <xsl:apply-templates/>
-  </xsl:copy>
-</xsl:template>
 
 </xsl:stylesheet>
diff -uNbr docbook-xsl-1.62.4/xhtml/graphics.xsl docbook-xsl-1.62.4.nosvg/xhtml/graphics.xsl
--- docbook-xsl-1.62.4/xhtml/graphics.xsl	2003-08-19 05:22:52.000000000 +0900
+++ docbook-xsl-1.62.4.nosvg/xhtml/graphics.xsl	2003-11-22 07:47:49.000000000 +0900
@@ -828,14 +828,6 @@
 </xsl:template>
 
 <xsl:template match="imageobject">
-  <xsl:choose>
-    <xsl:when xmlns:svg="http://www.w3.org/2000/svg"; test="svg:*">
-      <xsl:apply-templates/>
-    </xsl:when>
-    <xsl:otherwise>
-      <xsl:apply-templates select="imagedata"/>
-    </xsl:otherwise>
-  </xsl:choose>
 </xsl:template>
 
 <xsl:template match="imagedata">
@@ -1077,13 +1069,5 @@
 </xsl:template>
 
 <!-- ==================================================================== -->
-<!-- "Support" for SVG -->
-
-<xsl:template xmlns:svg="http://www.w3.org/2000/svg"; match="svg:*">
-  <xsl:copy>
-    <xsl:copy-of select="@*"/>
-    <xsl:apply-templates/>
-  </xsl:copy>
-</xsl:template>
 
 </xsl:stylesheet>