【发布时间】:2017-05-22 07:44:18
【问题描述】:
我正在使用 dita-ot 2.4。我需要在我的文档中添加一个新元素。它应该通过 XSL 转换转换为一组不同的元素。我创建了一个插件,它定义了一个新元素及其属性,并将其添加到现有主题模板中。我还在输出处理插件中添加了一些基本的 XSL 处理:
<xsl:attribute-set name="rootelement">
<xsl:attribute name="font-weight">bold</xsl:attribute>
</xsl:attribute-set>
<xsl:template match="rootelement">
<fo:inline xsl:use-attribute-sets="rootelement">
<xsl:call-template name="commonattributes"/>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
所以,现在我可以在我的文档中写下以下内容,它将以粗体显示(在 PDF 中):
<rootelement>
test
</rootelement>
但是,我最初的目标是为<rootelement> 创建一个转换,它会发出其他元素,例如,像这样:
<xsl:template match="rootelement">
<b>Some text:</b>
<xsl:value-of select="current()" />
<i>Some other text</i>
</xsl:template>
实际的转换有点复杂,涉及到表格,所以我不能只对这个元素应用显示属性。
是否可以在 DITA 中实现这种行为?我需要专业化吗?
编辑:澄清一下,这是一个似乎有效的样式表:
<xsl:template match="rootelement">
<xsl:text>
Text:
</xsl:text>
<fo:inline xsl:use-attribute-sets="rootelement">
<xsl:call-template name="commonattributes"/>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
rootelement 的每个实例都以“Text:”开头。
另一方面,此样式表不会产生预期的结果:
<xsl:template match="rootelement">
<i>
<xsl:text>
Text:
</xsl:text>
</i>
<fo:inline xsl:use-attribute-sets="rootelement">
<xsl:call-template name="commonattributes"/>
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
“文本:”部分没有以斜体打印,而是消失了。此外,只需将 <rootelement><i>Text: </i> some text</rootelement> 放入源 XML 即可按预期工作。
【问题讨论】: