[xsl] how to replace a node with a variable

Subject: [xsl] how to replace a node with a variable
From: "Paria Heidari" <pheidari@xxxxxxxxxxxxxx>
Date: Mon, 27 Sep 2004 10:13:11 -0400
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>&#xA;</xsl:text>
    <xsl:text>&#xA;</xsl:text>
    <xsl:for-each select="//CUSTOMER/child::*[count(child::*) &gt; 0]">
      <xsl:if test="generate-id(.) = generate-id(key('by-name',
name())[1])">
	<xsl:call-template name="printNode"/>
	<xsl:text>&#xA;</xsl:text>
	<xsl:text>&#xA;</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>&#x9;</xsl:text>
    </xsl:for-each>
    <xsl:if test="count(child::*[count(child::*)=0]) &gt; 0">
      <xsl:text>&#xA;</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) &gt; 0">
      <xsl:for-each select="child::*[count(child::*)=0]">
	<xsl:value-of select="."/>
	<xsl:text>&#x9;</xsl:text>
      </xsl:for-each>
      <xsl:text>&#xA;</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>
--+--

Current Thread