2

何百行ものテキストがあり、PDF に出力して次のように表示する必要がある XML ドキュメントでフォーマットされています。

LEFT TEXT.......................................................................RIGHT TEXT

XSLでこれを行う方法を発見しましたが、現在はFO出力中に処理命令として実行されています。XSL:

<xsl:template match="processing-instruction('leftrighttext')">
  <fo:block text-align-last="justify">
    <xsl:text>LEFT TEXT</xsl:text>
    <fo:leader leader-pattern="dots"/>
    <xsl:text>RIGHT TEXT</xsl:text>
  </fo:block>

XML がどのように見えるか (テーブルで使用されている):

<row>
<entry> <?leftrighttext?> </entry>
</row

望ましい出力:

LEFT TEXT........................................................................RIGHT TEXT
NEXT TEXT WITHIN TABLE...........................................................OTHER TEXT

私の質問は、次のように、スタイルシートに値を直接入力する代わりに、XML ドキュメントから呼び出される "LEFT TEXT" と "RIGHT TEXT" を取得するにはどうすればよいかということです。

<row>
<entry>LEFT TEXT <sometag> RIGHT TEXT</entry>
</row>
<row>
<entry>NEXT TEXT WITHIN TABLE <sometag> OTHER TEXT

作成できるタグ、またはタグの前のテキストと後のテキストを識別する文字列はありますか?それらの間にドット リーダーを入力しますか?

どんな助けでも大歓迎です。


要求された追加情報: 以下の回答に掲載されている XSLT を使用しました。変換しようとしている XML ドキュメントは次のとおりです。また、wsas が以下に投稿した XML の概要に従いました。何が足りないのか教えてください...

XML:

<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" schematypens="http://relaxng.org/ns/structure/1.0"?>
<?xml-model href="http://docbook.org/xml/5.0/rng/docbook.rng" type="application/xml" schematypens="http://purl.oclc.org/dsdl/schematron"?>
<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
    version="5.0">    
    <table>
        <tgroup cols="2">
            <colspec colnum="1" colname="col1" colwidth="235"/>
            <colspec colnum="2" colname="col2" colwidth="235"/>
            <thead>
                <row>
                    <entry align="center">LSP</entry>
                    <entry align="center">RSP</entry>
                </row>
            </thead>
            <tbody>
                <row>
                    <entry align="center" namest="col1" nameend="col2">(PF) Takeoff Briefing<?leftrighttext?>PERFORM</entry>
                </row>
            </tbody>
        </tgroup>
    </table>
</section>

これは私がスタイルシートの冒頭に持っているものです:

XSLT:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:date="http://exslt.org/dates-and-times"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
xmlns:d="http://docbook.org/ns/docbook"
exclude-result-prefixes="xs date"
extension-element-prefixes="date"
version="1.0">
<xsl:import href="http://docbook.sourceforge.net/release/xsl-ns/current/fo/docbook.xsl"/>
4

1 に答える 1

4

処理命令を使用するという元のアプローチに固執します。xsl:apply-templatesを使用して を構築するだけですfo:table-cell

例:

XML 入力

<doc>
    <row>
        <entry>LEFT TEXT <?leftrighttext?> RIGHT TEXT</entry>
    </row>
    <row>
        <entry>NEXT TEXT WITHIN TABLE <?leftrighttext?> OTHER TEXT</entry>
    </row>    
</doc>

XSLT1.0

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/*">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
                    <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="my-page">
                <fo:flow flow-name="xsl-region-body">
                    <fo:table>
                        <fo:table-body>
                            <xsl:apply-templates select="row"/>                            
                        </fo:table-body>
                    </fo:table>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="row">
        <fo:table-row>
            <xsl:apply-templates select="entry"/>
        </fo:table-row>
    </xsl:template>

    <xsl:template match="entry">
        <fo:table-cell>
            <fo:block text-align-last="justify">
                <xsl:apply-templates/>
            </fo:block>
        </fo:table-cell>
    </xsl:template>

    <xsl:template match="entry/text()">
        <xsl:value-of select="normalize-space()"/>
    </xsl:template>

    <xsl:template match="processing-instruction('leftrighttext')">
        <fo:leader leader-pattern="dots"/>
    </xsl:template>

</xsl:stylesheet>

XSL-FO 出力

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
      <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
         <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
      </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="my-page">
      <fo:flow flow-name="xsl-region-body">
         <fo:table>
            <fo:table-body>
               <fo:table-row>
                  <fo:table-cell>
                     <fo:block text-align-last="justify">LEFT TEXT<fo:leader leader-pattern="dots"/>RIGHT TEXT</fo:block>
                  </fo:table-cell>
               </fo:table-row>
               <fo:table-row>
                  <fo:table-cell>
                     <fo:block text-align-last="justify">NEXT TEXT WITHIN TABLE<fo:leader leader-pattern="dots"/>OTHER TEXT</fo:block>
                  </fo:table-cell>
               </fo:table-row>
            </fo:table-body>
         </fo:table>
      </fo:flow>
   </fo:page-sequence>
</fo:root>

レンダリングされた PDF

ここに画像の説明を入力


更新された例

更新 XML の例を見ると、デフォルトの名前空間 ( xmlns="http://docbook.org/ns/docbook") があることがわかります。すべきことは、XSLT でプレフィックスを使用してその名前空間を宣言し、XPath でそのプレフィックスを使用することです。

XSLT 2.0 を使用している場合は、XPath を変更せずに追加xpath-default-namespace="http://docbook.org/ns/docbook"することもできます。xsl:stylesheet

完全な XSLT (または tbody が作成されている場所のコンテキストを示すテンプレートでさえ) を示していないため、特定のものを推奨するのは難しいため、これは完全な推測です。

http://docbook.org/ns/docbook更新された XML を使用し、接頭辞 で名前空間を宣言する例を次に示しますdoc

(単純にするために、テーブルヘッダーなどを処理しようとしませんでした。)

XML 入力

<section xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
    version="5.0">    
    <table>
        <tgroup cols="2">
            <colspec colnum="1" colname="col1" colwidth="235"/>
            <colspec colnum="2" colname="col2" colwidth="235"/>
            <thead>
                <row>
                    <entry align="center">LSP</entry>
                    <entry align="center">RSP</entry>
                </row>
            </thead>
            <tbody>
                <row>
                    <entry align="center" namest="col1" nameend="col2">(PF) Takeoff Briefing<?leftrighttext?>PERFORM</entry>
                </row>
            </tbody>
        </tgroup>
    </table>
</section>

XSLT1.0

<xsl:stylesheet version="1.0" xmlns:doc="http://docbook.org/ns/docbook" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
    <xsl:output indent="yes"/>
    <xsl:strip-space elements="*"/>

    <xsl:template match="/*">
        <fo:root>
            <fo:layout-master-set>
                <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
                    <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
                </fo:simple-page-master>
            </fo:layout-master-set>
            <fo:page-sequence master-reference="my-page">
                <fo:flow flow-name="xsl-region-body">
                    <xsl:apply-templates/>
                </fo:flow>
            </fo:page-sequence>
        </fo:root>
    </xsl:template>

    <xsl:template match="doc:table">
        <fo:table>
            <fo:table-body>
                <xsl:apply-templates select="doc:tgroup/doc:tbody/doc:row"/>                            
            </fo:table-body>
        </fo:table>        
    </xsl:template>

    <xsl:template match="doc:row">
        <fo:table-row>
            <xsl:apply-templates select="doc:entry"/>
        </fo:table-row>
    </xsl:template>

    <xsl:template match="doc:entry">
        <fo:table-cell>
            <fo:block text-align-last="justify">
                <xsl:apply-templates/>
            </fo:block>
        </fo:table-cell>
    </xsl:template>

    <xsl:template match="doc:entry/text()">
        <xsl:value-of select="normalize-space()"/>
    </xsl:template>

    <xsl:template match="processing-instruction('leftrighttext')">
        <fo:leader leader-pattern="dots"/>
    </xsl:template>

</xsl:stylesheet>

XSL-FO 出力

<fo:root xmlns:doc="http://docbook.org/ns/docbook"
         xmlns:fo="http://www.w3.org/1999/XSL/Format">
   <fo:layout-master-set>
      <fo:simple-page-master master-name="my-page" page-width="8.5in" page-height="11in">
         <fo:region-body margin="1in" margin-top="1.5in" margin-bottom="1.5in"/>
      </fo:simple-page-master>
   </fo:layout-master-set>
   <fo:page-sequence master-reference="my-page">
      <fo:flow flow-name="xsl-region-body">
         <fo:table>
            <fo:table-body>
               <fo:table-row>
                  <fo:table-cell>
                     <fo:block text-align-last="justify">(PF) Takeoff Briefing<fo:leader leader-pattern="dots"/>PERFORM</fo:block>
                  </fo:table-cell>
               </fo:table-row>
            </fo:table-body>
         </fo:table>
      </fo:flow>
   </fo:page-sequence>
</fo:root>

レンダリングされた PDF

ここに画像の説明を入力

于 2015-07-30T18:25:10.027 に答える