2017-10-19 137 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