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

XSLT转换DITA map时audience属性值无法导出至输出文件

解决DITA Map转换中topichead的audience属性丢失问题

问题原因

你的XSLT模板在处理<topichead>节点时,没有复制audience属性——navtitle能正常导出说明节点的内容处理逻辑是正常的,只是属性传递环节遗漏了目标属性。

解决方案

针对<topichead>的处理模板,补充属性复制逻辑即可,有两种常用方式:

方式1:显式复制单个属性

在生成输出<topichead>元素的代码块中,添加对audience属性的处理:

<xsl:template match="topichead">
  <topichead>
    <!-- 仅复制audience属性 -->
    <xsl:if test="@audience">
      <xsl:attribute name="audience">
        <xsl:value-of select="@audience"/>
      </xsl:attribute>
    </xsl:if>
    <!-- 保留原有的navtitle处理逻辑 -->
    <xsl:if test="navtitle">
      <navtitle>
        <xsl:value-of select="navtitle/text()"/>
      </navtitle>
    </xsl:if>
    <xsl:apply-templates/>
  </topichead>
</xsl:template>

方式2:批量复制所有属性

如果需要保留<topichead>的全部原始属性,直接用<xsl:copy-of>复制所有属性:

<xsl:template match="topichead">
  <topichead>
    <!-- 复制当前节点的所有属性 -->
    <xsl:copy-of select="@*"/>
    <!-- 保留原有的navtitle处理逻辑 -->
    <xsl:if test="navtitle">
      <navtitle>
        <xsl:value-of select="navtitle/text()"/>
      </navtitle>
    </xsl:if>
    <xsl:apply-templates/>
  </topichead>
</xsl:template>

验证

修改完成后重新执行XSLT转换,检查输出文件中的<topichead>元素,应该能看到audience="Alaska"(或对应属性值)已正常输出。

内容的提问来源于stack exchange,提问作者pantherfan

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 17:55:57