Reputation: 31
If we say apply templates for a particular node , it ll apply in the entire xml wherever it finds that node/tag.
My issue is i ve a xml , where i need to apply templates based on condition , basically maintain some order.
Input xml :
enter code here
<step>
<note>..</note>
<para>..</para>
<table>
..
..
</table>
<note>...</note>
<table>
..
..
</table>
<table>
..
..
</table>
<note>...</note>
<text>...</text>
</step>
output should be ,
<fc:topic>
<fc:subTask id="S0EC0A941" lbl="E.">
<fc:para>..</fc:para>
<fc:text>...</fc:text>
<fc:note>..</fc:note>
<fc:table>
..
..
</fc:table>
<fc:note>...</fc:note>
<fc:table>
..
..
</fc:table>
<fc:table>
..
..
</fc:table>
<fc:note>...</fc:note>
</fc:subTask>
</fc:topic>
My XSLT is like this,
<xsl:template match="step">
<fc:topic>
<fc:subTask>
<xsl:if test="@id">
<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
</xsl:if>
<xsl:attribute name="lbl"><xsl:number format="A."/></xsl:attribute>
<xsl:apply-templates select="para"/>
<xsl:apply-templates select="text"/>
<xsl:apply-templates select="note"/>
<xsl:apply-templates select="table"/>
</fc:subTask>
</fc:topic>
Need to restructure the XSL based on the below condition ,
I want to apply the note template only if the note is not coming as the preceding or following sibling of table . If its following or preceding sibling of table then it should come in between the tables , below or above the table , just like in the output.
Thanks
Upvotes: 0
Views: 74
Reputation: 167781
Replace
<xsl:apply-templates select="para"/>
<xsl:apply-templates select="text"/>
<xsl:apply-templates select="note"/>
<xsl:apply-templates select="table"/>
with
<xsl:apply-templates select="para, text, note[not(preceding-sibling::*[1][self::table] | following-sibling::*[1][self::table])]"/>
<xsl:apply-templates select="table | note[preceding-sibling::*[1][self::table] or following-sibling::*[1][self::table]]"/>
Upvotes: 2