You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

XSLT DITA OT生成PDF时语言设置代码失效求助

Troubleshooting Your DITA OT XSLT Language-Specific PDF Output

Hey there, let's figure out why your language-controlled XSLT code isn't working as expected with DITA OT PDF generation. Here are the key checks and fixes to try out:

  • Verify the context of your @xml:lang test
    The @xml:lang in your xsl:when condition refers to the current context node—if that node doesn't actually have an xml:lang attribute (e.g., you're targeting a child element instead of the root <topic> or map node), the test will never match. Try explicitly targeting the correct node, like:

    <xsl:when test="/topic/@xml:lang = 'en'">
    

    Or even better, use DITA OT's built-in $dita.locale parameter, which directly uses the language set during the build process:

    <xsl:when test="$dita.locale = 'en'">
    
  • Fix case sensitivity issues
    DITA follows RFC 5646 for language codes, which are typically lowercase (e.g., en, fr instead of EN, FR). XSLT string comparisons are case-sensitive, so either adjust your test to match lowercase codes, or use the lower-case() function to normalize:

    <xsl:when test="lower-case(@xml:lang) = 'en'">
    
  • Check your attribute sets
    If your languagecontainer and languageblock attribute sets aren't properly defined (or are missing critical properties like position for absolute placement), your FO blocks might not appear in the PDF. Double-check their definitions, for example:

    <xsl:attribute-set name="languagecontainer">
      <xsl:attribute name="position">absolute</xsl:attribute>
      <xsl:attribute name="width">100%</xsl:attribute>
    </xsl:attribute-set>
    
  • Inspect the generated FO output
    Debug by generating just the FO file (use DITA OT parameter -Dgenerate.fo=true during the build) and open it in a text editor. If you don't see the corresponding <fo:block-container> blocks, your xsl:when conditions aren't matching. If the blocks are present but missing from the PDF, the issue is with your FO styling (e.g., incorrect top position, hidden visibility).

Here's a revised version of your code incorporating these fixes:

<!-- Use DITA OT's built-in locale parameter for reliability -->
<xsl:variable name="current-language" select="$dita.locale"/>

<xsl:choose>
  <xsl:when test="$current-language = 'en'">
    <fo:block-container xsl:use-attribute-sets="languagecontainer" top="25mm">
      <fo:block xsl:use-attribute-sets="languageblock">ENGLISH</fo:block>
    </fo:block-container>
  </xsl:when>
  <xsl:when test="$current-language = 'fr'">
    <fo:block-container xsl:use-attribute-sets="languagecontainer" top="55mm">
      <fo:block xsl:use-attribute-sets="languageblock">FRANÇAIS</fo:block>
    </fo:block-container>
  </xsl:when>
  <!-- Add a fallback for unhandled languages -->
  <xsl:otherwise>
    <fo:block-container xsl:use-attribute-sets="languagecontainer" top="25mm">
      <fo:block xsl:use-attribute-sets="languageblock">DEFAULT LANGUAGE</fo:block>
    </fo:block-container>
  </xsl:otherwise>
</xsl:choose>

内容的提问来源于stack exchange,提问作者Frank Manuela Thijssen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 03:08:26