2011-08-12 7 views
8

xsltファイルを作成しています。これはxmlをxsl-foに変換する必要があります。XSLTを使用してネストされた太字/イタリックタグ付きXSL-FOを作成する

XMLはそのようなものです:もちろん

<doc> 
    <par> 
    <point> 
     <text>some text</text> 
    </point> 
    </par> 
</doc> 

、文書の多くの段落やポイントがあります。

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" exclude-result-prefixes="fo"> 
    <xsl:output method="xml" version="1.0" omit-xml-declaration="no" indent="yes"/> 
    <xsl:param name="versionParam" select="'1.0'"/> 
    <xsl:template match="doc"> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     <fo:layout-master-set> 
     <fo:simple-page-master master-name="simpleA4" page-height="29.7cm" page-width="21cm" margin-top="2cm" margin-bottom="2cm" margin-left="2cm" margin-right="2cm"> 
      <fo:region-body margin="2cm"/> 
      <fo:region-before margin="0.2cm" extent="1.5cm"/> 
     </fo:simple-page-master> 
     </fo:layout-master-set> 
     <fo:page-sequence master-reference="simpleA4"> 
     <fo:static-content flow-name="xsl-region-before" margin-right="1cm"> 
      <fo:block text-align="start" margin-top="0.2cm"> 
      <fo:block text-align="end" margin-top="0.2cm"> 
       Page <fo:page-number/> of <fo:page-number-citation ref-id="terminator"/> 
      </fo:block> 
     </fo:static-content> 
     <fo:flow flow-name="xsl-region-body"> 
      <xsl:apply-templates select="par/point"/> 
      <fo:block id="terminator"/> 
     </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
    </xsl:template> 
    <xsl:template match="point"> 
    <fo:block font-size="16pt" space-after="5mm"> 
     <xsl:value-of select="tresc"/> 
    </fo:block> 
    </xsl:template> 
</xsl:stylesheet> 

が必要です。私は今、私はこのような、非常に簡単なXSLT文書を持っている例

<bold>bolded text</bold> and <italic>italic</italic> 

ための「テキスト」は、

<fo:block><fo:inline font-weight="bold">bolded text</fo:inline> and <fo:inline font-style="italic">italic</fo:inline> 

を与える必要がありますフォーマットする可能性を追加したいと思います別のテンプレート(太字、イタリック)を追加しますか?どのように私は "テキスト"ノードでそれを呼び出すはずですか?

私はいくつかの解決策が見つかりました:

<xsl:template match="//bold"> 
    <fo:inline font-weight="bold"> 
     <xsl:value-of select="current()"></xsl:value-of> 
    </fo:inline> 
</xsl:template> 

をしかし、それは私のために動作しませんでした。出力xsl-foにはfo:inlineは含まれません。

答えて

9

この例を見てください。それは、インラインノードの使用方法を明確に示しています。

[XSLT 1.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:template match="doc"> 
     <fo:root> 
      <fo:page-sequence> 
       <fo:flow> 
        <xsl:apply-templates select="par/point"/> 
       </fo:flow> 
      </fo:page-sequence> 
     </fo:root> 
    </xsl:template> 

    <xsl:template match="point"> 
     <fo:block font-size="16pt" space-after="5mm"> 
      <xsl:apply-templates select="node()"/> 
     </fo:block> 
    </xsl:template> 

    <xsl:template match="bold"> 
     <fo:inline font-weight="bold"> 
      <xsl:apply-templates select="node()"/> 
     </fo:inline> 
    </xsl:template> 

    <xsl:template match="italic"> 
     <fo:inline font-style="italic"> 
      <xsl:apply-templates select="node()"/> 
     </fo:inline> 
    </xsl:template> 

</xsl:stylesheet> 

<doc> 
    <par> 
     <point> 
      <text>some <bold>bold</bold></text> 
     </point> 
    </par> 
    <par> 
     <point> 
      <text>some <italic>italic <bold>bolded</bold></italic></text> 
     </point> 
    </par> 
</doc> 

が生成する:

<fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
    <fo:page-sequence> 
     <fo:flow> 
     <fo:block font-size="16pt" space-after="5mm"> 
      some <fo:inline font-weight="bold">bold</fo:inline> 
       </fo:block> 
     <fo:block font-size="16pt" space-after="5mm"> 
      some <fo:inline font-style="italic">italic <fo:inline font-weight="bold">bolded</fo:inline> 
      </fo:inline> 
       </fo:block> 
     </fo:flow> 
    </fo:page-sequence> 
</fo:root> 
+0

'冗長である= "()ノード" を選択します。 http://www.w3.org/TR/xslt#section-Applying-Template-Rulesから: "' select'属性がない場合、 'xsl:apply-templates'命令は、その子のすべての子プロセスを処理します現在のノード(テキストノードを含む)。 –

関連する問題