我試圖將一些文本添加到基於其「步驟」父項的「性能」屬性的段落中。使用XSL將文本添加到XML子元素,同時保留子元素的所有子元素和屬性
如果步驟被標記爲「性能=‘可選的’」我想生成的文本(對於低於第二步驟),以看起來像這樣:
「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()沒有按不尊重孩子和屬性?)
我已經得到了種類的clo使用下面的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>
你有沒有符合你'para'元素模板? – 2013-04-09 07:19:23