如何在最内层添加新节点 [英] How to add a new node at the innermost level
问题描述
在我的xsl中已经为para,graphic等元素定义了模板。例如:
In my xsl there are already templates defined for elements like para, graphic etc. Example below:
<xsl:template match="para">
<fo:block>
<xsl:apply-templates />
</fo:block>
</xsl:template>
但我想在最里面添加一个额外的节点特定的属性值。例如,如果元素的属性值为changeStatus = new / changed,我需要在其他节点中添加fo:change-bar-begin元素。示例xml:
But I want to add an extra node at the innermost level in case of a particular attribute value. For example, if the element has the attribute value of changeStatus = new/changed, I need to add 'fo:change-bar-begin' element inside the other nodes. Example xml:
<para changeStatus="new">
This is a paragraph that has change bars applied to the whole paragraph. </para>
输出应该是(这里:块节点来自xsl中的其他模板):
The output should be(here fo:block node is coming from the other templates in the xsl):
<pre><fo:block>
<fo:change-bar-begin change-bar-style="solid"/>
This is a paragraph that has change bars applied to the whole paragraph.
<fo:change-bar-end/></fo:block>
我尝试过:
我正在使用此代码,但在某些情况下,它是在外层添加节点,而在其他情况下,它正在删除其他模板中定义的节点(例如fo:block)。我需要它才能在最里面添加新元素。
< xsl:template match =* [@ changeStatus ='new'或@ changeStatus = '更改']>
< fo:change-bar-begin change-bar-style =solid/>
< xsl:apply-templates select =node()| @ */>
< fo:change-bar-end />
这里,para只是一个例子,我需要这个代码来处理很多元素,所以使用call-template不是选项。请建议最好的方法。
What I have tried:
I am using this code but for some cases, it is adding the node at outer level, while in other cases it is removing the nodes(e.g. fo:block) defined in other templates. I need it to just add the new element at the innermost level.
<xsl:template match="*[@changeStatus='new' or @changeStatus='changed']">
<fo:change-bar-begin change-bar-style="solid"/>
<xsl:apply-templates select="node() | @*" />
<fo:change-bar-end/>
Here, para is just an example and I need this code to work for many elements, so using call-template is not an option. Please suggest the best way to do it.
推荐答案
也许 XSLT < XSL:如果>元素 [ ^ ]可以提供任何帮助吗?
亲切。
Maybe XSLT <xsl:if> Element[^] could be of any help?
Kindly.
这篇关于如何在最内层添加新节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!