|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] how to replace a node with a variable
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
--+------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
--+--
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








