[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: how to replace a node with a variable

Subject: RE: how to replace a node with a variable
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 27 Sep 2004 16:02:57 +0100
xsl replace node
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:  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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.