3

xsltを使用してxsl-foドキュメントに変換しているxmlドキュメントがあります。私は長い間解決策を突き止めようとしてきたこのトリッキーな問題を抱えています...

私のソースxmlには、いくつかのタグが散在しています。結果のドキュメントでこれらを下線としてフォーマットしたいのですが、できませんでした。

私は次のようなコードを使用しようとしています:

<xsl:template match="//em">
  <fo:inline text-decoration="underline">
    <xsl:apply-templates select="*|text()"/>
  </fo:inline>
</xsl:template>

完全なXSLTは次のようになります。

<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:fo="http://www.w3.org/1999/XSL/Format"
  version="1.0">



  <!-- match em tags -->
  <xsl:template match="//em">
    <fo:inline text-decoration="underline">
      <xsl:apply-templates select="*|text()"/>
    </fo:inline>
  </xsl:template>
  <xsl:template match="//u">
    <fo:inline text-decoration="underline">
      <xsl:apply-templates select="*|text()"/>
    </fo:inline>
  </xsl:template>

  <!-- match b tags -->
  <xsl:template match="//b">
    <fo:inline font-weight="bold">
      <xsl:apply-templates select="*|text()"/>
    </fo:inline>
  </xsl:template>

  <xsl:template match="//br">
    <fo:block><xsl:text>&#xA;</xsl:text></fo:block>
  </xsl:template>

  <xsl:template match="briefs">
    <fo:root>
      <fo:layout-master-set>
        <fo:simple-page-master master-name="Evidence" page-width="8.5in" page-height="11in" margin="1in">
          <fo:region-body margin-bottom=".5in" margin-top=".5in" region-name="xsl-region-body" />
          <fo:region-before extent="1em" region-name="xsl-region-before" />
          <fo:region-after extent="1em" region-name="xsl-region-after" />
        </fo:simple-page-master>
      </fo:layout-master-set>
      <xsl:for-each select="brief">
        <fo:page-sequence master-reference="Evidence">
        <fo:static-content flow-name="xsl-region-before" font-family="Times">
           <fo:block font-size="10pt" text-align="center" color="#666666">
            <fo:inline font-style="italic"><xsl:value-of select="title"/></fo:inline> by <xsl:value-of select="author"/>
           </fo:block>
        </fo:static-content>

        <fo:static-content flow-name="xsl-region-after" font-family="Times" font-size="10pt">
          <fo:table>
            <fo:table-column />
            <fo:table-column column-width="1in" />
            <fo:table-body>
              <fo:table-row>
                <fo:table-cell>
                  <fo:block text-align="left" color="#666"><xsl:value-of select="copyright"/></fo:block>
                </fo:table-cell>
                <fo:table-cell>
                  <fo:block text-align="right" font-weight="bold">
                    Page <fo:page-number/>
                  </fo:block>
                </fo:table-cell>
              </fo:table-row>
            </fo:table-body>
          </fo:table>
        </fo:static-content>

        <fo:flow flow-name="xsl-region-body" font-family="Times">
          <fo:block font-size="14pt" text-align="center" text-transform="uppercase" border-before-width="2pt" border-before-color="black" border-before-style="double" border-after-width="1pt" border-after-color="black" border-after-style="solid" background-color="#ccc">
            <xsl:value-of select="title"/>
           </fo:block>

          <xsl:for-each select="heading">
            <xsl:choose>
              <xsl:when test="@level = 2">
                <fo:block font-size="11pt" font-weight="bold" keep-with-next="always" text-transform="uppercase" padding-before="1em">
                  <xsl:value-of select="title"/></fo:block>
              </xsl:when>
              <xsl:when test="@level = 3">
                <fo:block font-size="10pt" font-weight="normal" keep-with-next="always" text-transform="uppercase" padding-before="1em">
                  <xsl:value-of select="title"/></fo:block>
              </xsl:when>
              <xsl:otherwise>
                <fo:block font-size="12pt" font-weight="bold" keep-with-next="always" text-transform="uppercase" padding-before="1em">
                  <xsl:value-of select="title"/></fo:block>
              </xsl:otherwise>
            </xsl:choose>

            <xsl:for-each select="content/item">
              <xsl:choose>
                <xsl:when test="@type = 'card'">
                  <!--Print the taglines-->
                  <fo:block font-size="10pt" font-weight="bold" padding-before="1em" keep-with-next="always">
                    <!--<xsl:number value="position()" format="1" />. -->
                    <xsl:value-of select="tagline"/>
                  </fo:block>

                  <!--Print the citation-->
                  <fo:block font-size="10pt" font-style="italic" keep-with-next="always" keep-together.within-page="always" margin-left=".25in" padding-before=".5em">
                    <!--<xsl:number value="position()" format="1" />. -->
                    <xsl:value-of select="citation" disable-output-escaping="yes" />
                  </fo:block>

                  <!--Print the body-->
                  <fo:block font-size="10pt" keep-together.within-page="always" margin-left=".25in" padding-before=".5em">
                    <!--<xsl:number value="position()" format="1" />. -->
                    <xsl:value-of select="quote" disable-output-escaping="yes" />
                  </fo:block>

                </xsl:when>
                <xsl:otherwise>
                  <fo:block font-size="10pt" padding-before=".5em"><xsl:value-of select="."/></fo:block>
                </xsl:otherwise>
              </xsl:choose>
            </xsl:for-each>

          </xsl:for-each>


        </fo:flow>

      </fo:page-sequence>
      </xsl:for-each>
    </fo:root>
  </xsl:template>

</xsl:stylesheet>

誰かアイデアはありますか?本当にありがとう!!!!!

4

3 に答える 3

7

あなたのコードが実際にドキュメントで「ワイルド」になる場所、つまりマッチを実行する場所が私にはわかりません。<briefs>がルートノードの場合、<xsl:apply-templates select="*"/>ある時点でいくつかまたは同様のものが表示されると思います。それ以外の場合は、ルート一致で指定された出力のみ<em>を取得します(そして、 etc一致を適用することはありません)。

定義されている場合にのみ置換を使用してドキュメント全体を処理する場合、従来の一致は次のようになります。

<xsl:template match="@* | node()">
    <xsl:copy>
        <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
</xsl:template>

これはすべてのノードに一致し、カスケードされるため、より具体的な一致が見つかるまで、すべてのノードに対して実行されます。したがって、xsltを使用すると:

<xsl:template match="@* | node()">
  <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
  </xsl:copy>
</xsl:template>
<xsl:template match="bar">
  <BAR/>
</xsl:template>

ほとんどのノードは「そのまま」繰り返されますが、要素はすべて(属性/コンテンツなしで)<bar>置き換えられます。<BAR/>

これでも注意してください。子データが一致によって処理されることを期待する場合は、明示的にカスケードする必要があります(カスケードされない上記の例で示されているよう<bar>)。そして、私はあなたの試合で何も見ることができません。<xsl:apply-templates><briefs>

ついに; match="//em"冗長です。match="em"十分なはずです。

于 2009-09-26T07:51:57.420 に答える
1

スタイルシート全体が表示されないことは役に立ちませんが、一致構文はおそらくそうでmatch="em"はないはずmatch="//em"です。

于 2009-09-19T02:38:19.513 に答える
0

XSLTを宣言的ではなく、強制的に実行しているようです。for-eachMGは正解です。「-ing」を少なくして「 」-ingを増やすと、運が良くなると思いますapply-templates

マスタールートテンプレート内にテンプレートを適用していないため、すべてのemノードが一致していないようです。for-eachがあるすべての場所で、代わりにapply-templatesを使用する必要があると言いたくなりますが、それは少し学術的です。

于 2009-09-29T14:11:28.133 に答える