2017-10-19 142 views
1

翻譯文本時出現問題!XSL翻譯錯誤輸出

<text>This is a non breaking -</text> 
<text> 
    <span style=""> 
     <span style="">Testtext</span> 
    </span> 
    ‑ 
    <span style=""> 
     <span style=""> some other text</span> 
    </span> 
</text> 

這是.xml文件我從CK編輯器和我有一個非中斷連字符的跨度之間獲得,但宋體不能顯示在我的.pdf文件這個非換連字符。我不允許更改.pdf的字體,因此我想將不分行連字符翻譯爲「正常」連字符。

<xsl:template match="text"> 
     <fo:block> 
      <xsl:choose> 
       <xsl:when test="not(*) and contains(text(), '&#8209;')"> 
        <xsl:value-of select="translate(text(), '&#8209;' , '-')"/> 
       </xsl:when> 
       <xsl:otherwise> 
        <xsl:if test="contains(text(), '&#8209;')"> <!-- Here is my problem --> 
         <xsl:value-of select="translate(text(), '&#8209;' , '-')"/> 
         <xsl:apply-templates /> 
        </xsl:if> 
        <xsl:if test="not(contains(text(), '&#8209;'))"> 
         <xsl:apply-templates/> 
        </xsl:if> 
       </xsl:otherwise> 
      </xsl:choose> 
     </fo:block> 
</xsl:template> 

我現在的問題是,在if與評論here is my problem,當我在此之前是輸出不應用模板後:

This is a non breaking - //thats ok 
-Testtext# some other text //thats not 

但如果我aplly他們他們<xsl:value-of select=....沒有按沒有工作。

它應該是這樣的:

This is a non breaking - 
Testtext- some other text 

回答

1

爲了避免text()選擇多個項目的序列(我認爲這是在這裏造成故障),你可以嘗試應用直接翻譯功能文本節點,如下所示:

<xsl:template match="text//text()[contains(.,'&#8209;')]"> 
    <xsl:value-of select="translate(., '&#8209;' , '-')"/> 
</xsl:template> 
+0

完美,這是一個我沒有想到的點,像一個魅力 – glove40