2016-04-14 9 views
1

私はFOPでPDFを生成しています。 PDFには、XMLタグの間にいくつかの単純なHTML(すなわち<p> <strong> <em>)を含むアンケートセクションが含まれています。私の解決策は、<p>タグの間のすべてをスタイルするなど、XSLファイル内のこれらのタグにテンプレートを適用することでした。私は今、基本的なテンプレートを設定しており、XSLファイルがXML内の<p>タグを見つける方法に関する問題にぶつかっていると思います。私は、HTMLタグは別のタグ内にあるので、私のXSLは期待どおりに動作しないと思います。私は疑問に思っています:XSLテンプレートを使ってこれらの内部HTMLタグをどのようにスタイルしますか?fop/xslファイル内のHTML

XMLは次のように生成されます。 <QuestionText>タグ内にHTMLタグが表示されます。

<xml> 
    <Report> 
     <Stuff> 
      <BasicInfo> 
       <InfoItem> 
        <InfoName>ID</InfoName> 
        <InfoData>555</InfoData> 
       </InfoItem> 
       <InfoItem> 
        <InfoName>Name</InfoName> 
        <InfoData>Testing</InfoData> 
       </InfoItem> 
      </BasicInfo> 

      <SubReports title="Employee Reports"> 
       <SubReport> 
        <Question> 
         <QuestionText> 
          <p>1. Are the pads secure?</p> 
         </QuestionText> 
         <AnswerText>Yes</AnswerText> 
        </Question> 
        <Question> 
         <QuestionText> 
          <p> 
           2. <strong>Are the pads in good shape?</strong>&nbsp; 
          </p> 
         </QuestionText> 
         <AnswerText>Yes</AnswerText> 
        </Question> 
       </SubReport> 
      </SubReports> 
     </Stuff> 
    </Report> 
</xml> 

その後、私はXML

<xsl:template match="Stuff"> 
    <fo:block> 
    <fo:block font-size="32pt" text-align="center" font-weight="bold">Report</fo:block> 
    </fo:block> 
<xsl:apply-templates/> 
</xsl:template> 

<xsl:template match="SubReports"> 
    <xsl:for-each select="SubReport"> 
    <xsl:for-each select="Question"> 
     <fo:block xsl:use-attribute-sets="question"><xsl:apply-templates /></fo:block> 
     <fo:block xsl:use-attribute-sets="answer"><xsl:value-of select="AnswerText" /></fo:block> 
    </xsl:for-each> 
    </xsl:for-each> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText"> 
    <fo:block><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/p"> 
    <fo:block padding-before="10pt"><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/strong"> 
    <fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

<xsl:template match="SubReports/SubReport/Question/QuestionText/em"> 
    <fo:inline font-style="italic"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

のスタイルをXSLテンプレートを持つには、HTMLタグの正しい場所へxsl:templatesポインティングの一致タグはありますか?もしそうでなければ、どこで私はそれを指すべきですか?ありがとうございました!

答えて

3

瞬間に、あなたのテンプレートマッチはmatch属性に

<xsl:template match="SubReports/SubReport/Question/QuestionText/strong"> 

を要素への完全なパスを持っている。しかし、これは、それはp要素の子である場合にstrong要素とは一致しません。今、あなたはこれを行うことができます...

<xsl:template match="SubReports/SubReport/Question/QuestionText/p/strong"> 

しかし、実際にここでフルパスを指定する必要はありません。非常に特定の要素に一致させたいのでない限りはありません。このテンプレートマッチもやります。

<xsl:template match="strong"> 

だから、あなたはあなたがまた、複数のネストされたHTMLタグの場合にはそう、この作品をxsl:apply-templatesを使用しているこれらの代わりに

<xsl:template match="p"> 
    <fo:block padding-before="10pt"><xsl:apply-templates /></fo:block> 
</xsl:template> 

<xsl:template match="strong"> 
    <fo:inline font-weight="bold"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

<xsl:template match="em"> 
    <fo:inline font-style="italic"><xsl:apply-templates/></fo:inline> 
</xsl:template> 

であなたの現在のテンプレートを置き換えることができます。例えば、<p><strong><em>Test</em></strong></p>