RE: [xsl] how to replace a node with a variable

Subject: RE: [xsl] how to replace a node with a variable
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 27 Sep 2004 16:02:57 +0100
I see "customers" and I see "CUSTOMER" but I don't see "customer". What
exactly did you want to generalize?

The answer is probably along the lines *[local-name()=$param]

Your uses of "//" look pretty haphazard in this stylesheet; and you can
replace the predicate [count(child::*) > 0] by [*].

Michael Kay 
http://www.saxonica.com/

> -----Original Message-----
> From: Paria Heidari [mailto:pheidari@xxxxxxxxxxxxxx] 
> Sent: 27 September 2004 15:13
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] 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>&#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