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

RE: RE: Convert string to a list of nodes

Subject: RE: RE: Convert string to a list of nodes
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Tue, 4 Dec 2001 10:56:43 -0500
convert list to string
here are two approaches to what I think your asking for:

approach 1:  (supplying the values pre-loaded into the att list constructor
string)

the xml:
<xml>
<width>20</width>
<class>label</class>
</xml>

the xsl: (updates only)
	...
	<xsl:template match="/"><xsl:apply-templates /></xsl:template>

	<xsl:template match="xml">
		<xsl:call-template name="build-attribute-list">
			<xsl:with-param name="src-attribute-list">
			(width,<xsl:apply-templates select="//width"/>)
			(class,<xsl:apply-templates select="//class"/>)
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="width">
		<xsl:value-of select="text()"/>
	</xsl:template>
	
	<xsl:template match="class">
		<xsl:value-of select="text()"/>
	</xsl:template>
	...

the output:
<attribute-list>
   <attribute name="width" value="20" />
   <attribute name="class" value="label" />
</attribute-list>



approach 2:  (letting the constructor resolve the value based on the
attribute name via a template match)


the xsl: (updates only)
	...
	<xsl:template match="/"><xsl:apply-templates /></xsl:template>
	<xsl:template match="xml">
		<xsl:call-template name="build-attribute-list">
			<xsl:with-param name="src-attribute-list">
			(width,"")
			(class,"")
			</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<xsl:template match="width">
		<xsl:value-of select="text()"/>
	</xsl:template>
	
	<xsl:template match="class">
		<xsl:value-of select="text()"/>
	</xsl:template>
	...
      	<xsl:template name="__att-list-constructor">
            	<!-- recursive worker template for template
build-att-list-constructor -->

            	<!-- attribute-list = '(n,v)(n,v)(n,v) ... ' -->
            	<xsl:param name="attribute-list" />

           		 <!-- grabs the first n-v pair -->
           		 <xsl:variable name="pair" select="substring-before(
substring-after( $attribute-list,'(' ), ')' )"/>
            	<xsl:if test="contains($pair,',') and $pair != '' ">
               	 	<xsl:element name="attribute" >
                	 		<xsl:variable name="the-name"
select="normalize-space( substring-before($pair,',') )"/>
                     			<xsl:attribute
name="name"><xsl:value-of select="$the-name"/></xsl:attribute>
                    	 		<xsl:variable name="the-value">
                     				<xsl:apply-templates
select="//*[local-name()=$the-name]"/>
                     			</xsl:variable> 
                     			<xsl:attribute name="value"
><xsl:value-of select="normalize-space($the-value)"/></xsl:attribute>
                		</xsl:element>
                		<xsl:call-template
name="__att-list-constructor">
                   		 	<xsl:with-param
name="attribute-list" select="substring-after( $attribute-list, concat(
substring-after( $pair, ',' ), ')' ) )"/>
               		 </xsl:call-template >
            	</xsl:if>
      	</xsl:template>
	...

the output:
<attribute-list>
   <attribute name="width" value="20" />
   <attribute name="class" value="label" />
</attribute-list>


If your going to do something like the second approach, then I'd re-engineer
the "__att-list-constructor" template to only take in your delimeted name
list ... which I guess you already did(?).

-Jeff


















 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.