XSLT DITA OT生成PDF时语言设置代码失效求助
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:langtest
The@xml:langin yourxsl:whencondition refers to the current context node—if that node doesn't actually have anxml:langattribute (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.localeparameter, 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,frinstead ofEN,FR). XSLT string comparisons are case-sensitive, so either adjust your test to match lowercase codes, or use thelower-case()function to normalize:<xsl:when test="lower-case(@xml:lang) = 'en'">Check your attribute sets
If yourlanguagecontainerandlanguageblockattribute sets aren't properly defined (or are missing critical properties likepositionfor 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=trueduring the build) and open it in a text editor. If you don't see the corresponding<fo:block-container>blocks, yourxsl:whenconditions aren't matching. If the blocks are present but missing from the PDF, the issue is with your FO styling (e.g., incorrecttopposition, 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

