I am new to the xslt.
- **Here is my input xml.**
<root>
<MilleniumCreditCard>
<Limit>20</Limit>
<overdraft>yes</overdraft>
</MilleniumCreditCard>
<VisaCreditCard>
<Limit>30</Limit>
<overdraft>yes</overdraft>
</VisaCreditCard>
<OtherTypeCreditCard>
<Limit>40</Limit>
<overdraft>yes</overdraft>
</OtherTypeCreditCard>
</root>
As we can see we have 3 types of credit card.
But at a time only one type of card can come in the input xml.
So the actual input xml would for example.
<root>
<MilleniumCreditCard>
<Limit>20</Limit>
<overdraft>yes</overdraft>
</MilleniumCreditCard>
</root>
I need to fetch the Limit and overdraft value for the same. but as I don't know which card will be coming , I have do a logic in my common template as shown below.
Hence I have tried to write a common template
1st I am calling the template like below
<output>
<Limit>
<xsl:call-template name="commontemplate">
<xsl:with-param name="inputname" select ="'Limit'"
</xsl:call-template>
</Limit>
<overdraft>
<xsl:call-template name="commontemplate">
<xsl:with-param name="inputname" select ="'overdraft'"
</xsl:call-template>
</overdraft>
</output>
Now my common template as below
<xsl:template name="commontemplate">
<xsl:param name="inputname" />
<xsl:choose>
<xsl:when test="root/MilleniumCreditCard != '' " />
<xsl:value-of select="root/MilleniumCreditCard/$inputname" />
</xsl:when>
<xsl:when test="root/VisaCreditCard != '' " />
<xsl:value-of select="root/VisaCreditCard/$inputname" />
</xsl:when>
<xsl:when test="root/OtherTypeCreditCard != '' " />
<xsl:value-of select="root/OtherTypeCreditCard/$inputname" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="''">
</xsl:otherwise>
</xsl:choose>
</xsl:template>
but I am , getting blank value for Limit tag in output. but I want to get the value like below .
<output>
<Limit>20</Limit>
<overdraft>yes</overdraft>
</output>
Can anybody help me with how to achieve this? I will greatly appreciate for this help
This is rather confusing. If the input will always have details of a single card only, you could do simply: