I have a xml file like this,
<content>
<ol>
<li> List<span style="color: rgb(255,0,255);">The scopeeeee of</span>this project is
<ol>
<li>nested list1</li>
<li>nested <span style="color: rgb(255,0,255);">The scope of this project is</span> list1</li>
<li>nested list1</li>
<li>nested list1</li>
<li>nested list1</li>
</ol>
</li>
<li>
<p>List<span style="color: rgb(255,0,255);">The scope of this project is to:</span></p>
</li>
<li>
<p>List<span style="color: rgb(255,0,255);">The scope of this project is to:</span></p>
</li>
</ol>
</content>
I need to transform above xml to following xml using XSLT
expected output,
<content>
<orderedList>
<liItem>
<para>List<c type="color: rgb(255,0,255);">The scopeeeee of this project is to:</c>jkhsdlkjfh</para>
</liItem>
<orderedList>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested <c type="color: rgb(255,0,255);">The scope of this project is</c>list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
<liItem>
<para>nested list1</para>
</liItem>
</orderedList>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para>
</liItem>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para>
</liItem>
</orderedList>
</content>
As you can see, the text content and span nodes within li items has to cover with <para>
node in output.
I have written following xsl to get this output,
<xsl:template match="ol">
<orderedList>
<xsl:apply-templates/>
</orderedList>
</xsl:template>
<xsl:template match="li[not(descendant::ol)]" >
<liItem>
<para>
<xsl:apply-templates />
</para>
</liItem>
</xsl:template>
<xsl:template match="li[descendant::ol]" >
<liItem>
<para>
<xsl:apply-templates select="node()[parent::li][following-sibling::ol]"/>
</para>
</liItem>
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="span">
<c type="{@style}">
<xsl:apply-templates/>
</c>
</xsl:template>
<xsl:template match="li/p">
<xsl:apply-templates />
</xsl:template>
The only problem of above xsl is comes when it has <ol>
inside another <ol>
item. I'm struggling to find a way add <para>
node to the text content which placed between <li>
and <ol>
nodes.
current output is follows,
<content>
<orderedList>
<liItem>
<para> List<c type="color: rgb(255,0,255);">The scopeeeee of</c>this project is</para>
</liItem> List<c type="color: rgb(255,0,255);">The scopeeeee of</c>this project is
<orderedList>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested <c type="color: rgb(255,0,255);">The scope of this project is</c>list1</para></liItem>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested list1</para></liItem>
<liItem><para>nested list1</para></liItem>
</orderedList>
<liItem><para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para></liItem>
<liItem><para> List<c type="color: rgb(255,0,255);">The scope of this project is to:</c></para></liItem>
</orderedList>
</content>
can anyone suggest me a way how can I modify my code to get the expected output..