Passing a node name to generic template
Let me explain the scenario.
I have written a generic template which copies all the element from the source tree . I want to add a logic to filter a node in the output tree which is passed as an argument .
Here's the xsl code : -
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="exclude-node" select="'amount'"></xsl:param>
<xsl:template match="*">
<xsl:choose>
<xsl:when test="local-name()=$exclude-node">
<xsl:call-template name="AnotherTemplate"></xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:copy-of select="@*"></xsl:copy-of>
<xsl:apply-templates></xsl:apply-templates>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="AnotherTemplate">
<xsl:param name="inputData"></xsl:param>
</xsl:template>
</xsl:stylesheet>
input xml :
<?xml version="1.0" encoding="UTF-8"?>
<departments>
<employee1>
<salary>
<amount>30</amount>
</salary>
</employee1>
<employee2>
<amount>
<amount>40</amount>
<currency>USD</currency>
</amount>
</employee2>
</departments>
Problem -
I can use the below statment to see if the context node is same as the argument .
<xsl:when test="local-name()=$exclude-node">
In the xml , <amount> contains a child node "amount" , i have to call Another Template for node <amount> which does not contains the any child node amount.
Since the node name is treated as a string , iam not able to write any xpath expression.
Hope iam clear with the explantion.
Let me know if this is feasible without using any dynamic xsl.
Thanks,
Arun
|