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>
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>
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>
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.