2016-07-21 42 views
0

我有一個這樣的XML:的Apache FOP XSL/XSLT - 使文本生成的PDF大膽

<?xml version="1.0" encoding="UTF-8"?> 
<TermsAndConditions> 
     <clause><clausetext>Terms and Conditions of Supply - Please read carefully</clausetext></clause> 
     <clause><clausetext>Available only to <bold>customers who have an existing</bold> account.</clausetext></clause> 
</TermsAndConditions> 

和樣式表是:

<fo:page-sequence master-reference="simple" > 
     <fo:flow flow-name="xsl-region-body">  
     <xsl:for-each select="data/TermsAndConditions/clause"> 
       <fo:block font-size="10pt" font-family="Arial" color="#6d6e71"><xsl:value-of select="clausetext" /> 
</fo:block> 
       <fo:block font-size="10pt" font-family="Arial" line-height="10pt" space-after.optimum="3pt" text-align="justify">&#0160;</fo:block> 
     </xsl:for-each> 
    </fo:flow> 
</fo:page-sequence> 

如何去使文字標籤< bold> </bold>在生成的pdf中以粗體顯示?目前,我可以看到這些條款,但文本是正常的。

進一步就此,我試着用w3schools.com的tryit編輯器類似的事情: [http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=tryxsl_if]

與下面的樣式表:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:template match="/"> 
    <html> 
    <body> 
    <xsl:apply-templates mode="tttt" /> 
    </body> 
    </html> 
</xsl:template> 

    <xsl:template match="bold" mode="tttt"> 
    <b><xsl:value-of select="." /></b> 
    </xsl:template> 
</xsl:stylesheet> 

和我得到的輸出所需。

+0

告訴你產生hrml樣式表。您至少需要使用Apache FOP的XSL FO –

+0

我正在使用xsl fo。第二個樣式表是基於第一個樣式表作爲概念證明。 – user2260040

回答

2

<b>是HTML語法,用於FO這可能應改爲:

<xsl:template match="bold" mode="tttt"> 
    <fo:inline font-weight="bold"><xsl:value-of select="." /></fo:inline> 
    </xsl:template> 
</xsl:stylesheet> 
+0

@ user2260040,你沒有接受很多答案,這就是所謂的「謝謝」的方式 - 這個答案對你有幫助嗎,或者我們能做些什麼來幫助你? –