Click here to Skip to main content
15,887,262 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

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):

XML
<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.
Posted
Updated 13-Oct-17 0:47am
v2

1 solution

Maybe XSLT <xsl:if> Element[^] could be of any help?
Kindly.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900