Hi,
I need to change the following xslt so instead of the hard-coded
'customer' I can use in the pass in variable. Is there an easy way to do
this?
I'd appreciate any suggestions.
-----------------------------------
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format">
<xsl:key name="by-name" match="//customers/CUSTOMER/*" use="name()"/>
<xsl:template match="customers">
<xsl:apply-templates select="CUSTOMER"/>
<xsl:text>
</xsl:text>
<xsl:text>
</xsl:text>
<xsl:for-each select="//CUSTOMER/child::*[count(child::*) > 0]">
<xsl:if test="generate-id(.) = generate-id(key('by-name',
name())[1])">
<xsl:call-template name="printNode"/>
<xsl:text>
</xsl:text>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="CUSTOMER">
<xsl:call-template name="printValues"/>
</xsl:template>
<xsl:template name="printHeaders">
<xsl:for-each select="child::*[count(child::*)=0]">
<xsl:value-of select="name()"/>
<xsl:text>	</xsl:text>
</xsl:for-each>
<xsl:if test="count(child::*[count(child::*)=0]) > 0">
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="printValues">
<xsl:if test="position() = 1">
<xsl:call-template name="printHeaders"/>
</xsl:if>
<xsl:variable name="empty">
<xsl:for-each select="child::*[count(child::*)=0]">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:variable>
<xsl:if test="string-length($empty) > 0">
<xsl:for-each select="child::*[count(child::*)=0]">
<xsl:value-of select="."/>
<xsl:text>	</xsl:text>
</xsl:for-each>
<xsl:text>
</xsl:text>
</xsl:if>
</xsl:template>
<xsl:template name="printNode">
<xsl:for-each select="key('by-name',name())/child::*">
<xsl:call-template name="printValues"/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Many thanks,
Paria