我正在尝试根据其“步骤”父级的“性能”属性向段落添加一些文本。
如果一个步骤被标记为 'performance="optional"' 我希望生成的文本(对于下面的第二步)看起来像这样:
“2.(可选)这是第 2 步……”
<procedure>
<step id="step_lkq_c1l_5j">
<para>This is step 1, which is required.</para>
</step>
<step performance="optional">
<para>This is step 2, which is optional, unlike <xref linkend="step_lkq_c1l_5j"/>.
<note>
<para>I don't want to lose this note in my transformation.</para>
</note>
</para>
</step>
<step>
<para>This is step 3.</para>
</step>
</procedure>
我尝试使用 Xpath 匹配我的节点并对其进行修改:<xsl:template match="step[@performance='optional']/child::para[position()=1]">
然后使用 concat() 尝试添加我的可选文本,但我会丢失外部参照链接(可能是因为 concat() 不尊重子节点和属性?)
使用以下 xsl 自定义,我已经接近了我想要的,但是(可选)文本位于段落之外,这会将步骤文本下降一行,有时会与页面内容中断。我真正想要的是在第一段中生成的文本。
有人有建议吗?
<!-- Add "(Optional) " to steps that have the performance="optional" attribute set -->
<xsl:template match="procedure/step|substeps/step">
<xsl:variable name="id">
<xsl:call-template name="object.id"/>
</xsl:variable>
<xsl:variable name="keep.together">
<xsl:call-template name="pi.dbfo_keep-together"/>
</xsl:variable>
<fo:list-item xsl:use-attribute-sets="list.item.spacing">
<xsl:if test="$keep.together != ''">
<xsl:attribute name="keep-together.within-column"><xsl:value-of
select="$keep.together"/></xsl:attribute>
</xsl:if>
<fo:list-item-label end-indent="label-end()">
<fo:block id="{$id}">
<!-- dwc: fix for one step procedures. Use a bullet if there's no step 2 -->
<xsl:choose>
<xsl:when test="count(../step) = 1">
<xsl:text>•</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="." mode="number">
<xsl:with-param name="recursive" select="0"/>
</xsl:apply-templates>.
</xsl:otherwise>
</xsl:choose>
</fo:block>
</fo:list-item-label>
<xsl:choose>
<xsl:when test="@performance='optional'">
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:text>(Optional) </xsl:text>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</xsl:when>
<xsl:otherwise>
<fo:list-item-body start-indent="body-start()">
<fo:block>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</xsl:otherwise>
</xsl:choose>
</fo:list-item>
</xsl:template>