2016-08-10 2 views
0

質問:FO:どのように私はこのエラー「FOインラインでの有効な子ではありませんXSL 『:解決できますか?XSL:FOなぜinlineは "fo:table"の有効な子ではありませんか?これをどうすれば解決できますか?

<?xml version="1.0" encoding="UTF-8"?> 
<diffreport> 
<css /> 
<diff> 
    <table border="1" cellpadding="1" cellspacing="1" style="width:500px"> 
     <caption>This is the table caption</caption> 
     <tbody> 
      <tr> 
       <td> 
        <span class="diff-html-removed" id="removed-diff-0"  previous="first-diff" 
         changeId="removed-diff-0" next="added-diff-0">one</span> 
        <span class="diff-html-added" id="added-diff-0" previous="removed-diff-0" 
         changeId="added-diff-0" next="removed-diff-1">uno</span> 
       </td> 
       <td> 
        <span class="diff-html-removed" id="removed-diff-1" previous="added-diff-0" 
         changeId="removed-diff-1" next="added-diff-1">two</span> 
        <span class="diff-html-added" id="added-diff-1" previous="removed-diff-1" 
         changeId="added-diff-1" next="last-diff">dos</span> 
       </td> 
      </tr> 
      <tr> 
       <td>three</td> 
       <td>four</td> 
      </tr> 
     </tbody> 
    </table> 
    <p /> 
</diff> 
</diffreport> 
:テーブル』を

は、私は次のようになり、簡単なテーブルとの文書を持っていると仮定

私は、XSL作成しました:。このようになりますテンプレートファイルFOを

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
    <fo:root xmlns:fo="http://www.w3.org/1999/XSL/Format"> 
     <fo:layout-master-set> 
      <fo:simple-page-master master-name="default-page" 
       page-height="11in" page-width="8.5in" margin-left="0.6in" 
       margin-right="0.6in" margin-top="0.79in" margin-bottom="0.79in"> 
       <fo:region-body /> 
      </fo:simple-page-master> 
     </fo:layout-master-set> 
     <fo:page-sequence master-reference="default-page"> 
      <fo:flow flow-name="xsl-region-body"> 
       <fo:block> 
        <fo:block font-size="180%" font-weight="bold" text-align="center"> 
         <xsl:text>Report</xsl:text> 
        </fo:block> 
        <fo:block> 
         <xsl:apply-templates /> 
        </fo:block> 

       </fo:block> 
      </fo:flow> 
     </fo:page-sequence> 
    </fo:root> 
</xsl:template> 
<!-- xsl report colors --> 
<xsl:template match="span[@class='diff-html-added']"> 
    <fo:inline color="green" background-color="#ccffcc"> 
     <xsl:value-of select="." /> 
    </fo:inline> 
</xsl:template> 
<xsl:template match="span[@class='diff-html-removed']"> 
    <fo:inline color="red" text-decoration="line-through" 
     background-color="#fdc6c6"> 
     <xsl:value-of select="." /> 
    </fo:inline> 
</xsl:template> 

<!-- Table --> 
<xsl:template match="table"> 
    <xsl:apply-templates /> 
</xsl:template> 

<xsl:template match="tbody"> 
    <fo:table space-before="0.5em" space-after="0.5em" 
     table-layout="fixed"> 
     <xsl:for-each select="tr[1]/th|tr[1]/td"> 
      <xsl:apply-templates /> 
     </xsl:for-each> 
     <fo:table-body> 
      <xsl:apply-templates /> 
     </fo:table-body> 
    </fo:table> 
</xsl:template> 

<xsl:template match="tr"> 
    <fo:table-row> 
     <xsl:if test="@space-before != ''"> 
      <xsl:attribute name="space-before"><xsl:value-of select="@space-before" /></xsl:attribute> 
     </xsl:if> 
     <xsl:if test="@class='graybar'"> 
      <xsl:attribute name="background-color">#ddd</xsl:attribute> 
     </xsl:if> 
     <xsl:apply-templates /> 
    </fo:table-row> 
</xsl:template> 

<xsl:template match="th"> 
    <fo:table-cell font-weight="bold" text-align="center"> 
     <xsl:if test="ancestor::table/@border &gt; 0"> 
      <xsl:attribute name="border-style">solid</xsl:attribute> 
      <xsl:attribute name="border-width">1pt</xsl:attribute> 
     </xsl:if> 
     <fo:block> 
      <xsl:apply-templates /> 
     </fo:block> 
    </fo:table-cell> 
</xsl:template> 

<xsl:template match="td"> 
    <fo:table-cell> 
     <xsl:if test="ancestor::table/@border &gt; 0"> 
      <xsl:attribute name="border-style">solid</xsl:attribute> 
      <xsl:attribute name="border-width">1pt</xsl:attribute> 
     </xsl:if> 
     <fo:block> 
      <xsl:call-template name="set-alignment" /> 
      <xsl:apply-templates /> 
     </fo:block> 
    </fo:table-cell> 
</xsl:template> 

<xsl:template name="set-alignment"> 
    <xsl:choose> 
     <xsl:when test="@align='left' or contains(@class,'left')"> 
      <xsl:attribute name="text-align">start</xsl:attribute> 
     </xsl:when> 
     <xsl:when test="@align='center' or contains(@class,'center')"> 
      <xsl:attribute name="text-align">center</xsl:attribute> 
     </xsl:when> 
     <xsl:when test="@align='right' or contains(@class,'right')"> 
      <xsl:attribute name="text-align">end</xsl:attribute> 
     </xsl:when> 
    </xsl:choose> 
</xsl:template> 
</xsl:stylesheet> 

を、私はこのエラー org.apache.fop.fo.ValidationException(エラー、未知の場所)が得続ける:「{を} "inline"は "fo:table"の有効な子ではありません!

xslからこれらのコードブロックを削除すると、エラーは消えますが、なぜこのコードが機能しないのかを理解するためには本当に助けが必要です。

<xsl:template match="span[@class='diff-html-added']"> 
    <span style="color:green; background-color: #ccffcc;"> 
    <xsl:value-of select="."/></span> 
</xsl:template> 

インラインはなぜ「fo:table」の子ではないのですか? xslテンプレートを修正してスパンクラスがテーブルで機能するようにするには、何が必要ですか?

+0

あなたがfoが生成されます:テーブル/ fo:inline xsl:for-each select = "tr [1]/th | tr [1]/td" '命令。この構造はXSL-FOでは使用できません。 fo:tableの直接の子は '(table-column *、table-header?、table-footer?、table-body +)'でなければなりません。 – tmakita

答えて

1

生成のfo:表はあなたの問題を解決します:FOの後、テーブル本体:テーブルヘッダとFO

<!-- Table --> 
<xsl:template match="table"> 
    <fo:table-and-caption> 
     <fo:table-caption> 
      <xsl:apply-templates select="caption"/> 
     </fo:table-caption> 
     <xsl:apply-templates select="tbody"/> 
    </fo:table-and-caption> 
</xsl:template> 

<xsl:template match="caption"> 
    <fo:block> 
     <xsl:apply-templates/> 
    </fo:block> 
</xsl:template> 

<xsl:template match="tbody"> 
    <fo:table space-before="0.5em" space-after="0.5em" table-layout="fixed"> 
     <fo:table-header> 
      <xsl:apply-templates select="tr[1]"/> 
     </fo:table-header> 
     <fo:table-body> 
      <xsl:apply-templates select="tr[position() &gt; 1]"/> 
     </fo:table-body> 
    </fo:table> 
</xsl:template> 

結果:

enter image description here

+0

ありがとうございました。あなたは人生の節約者です。 –

関連する問題