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

RE: Convert string to a list of nodes

Subject: RE: Convert string to a list of nodes
From: Jeff Beadle <Jbeadle@xxxxxxxx>
Date: Tue, 4 Dec 2001 08:54:58 -0500
convert string to list
I wrote a recursive template (this is a modified form) that does something
similar to what you want.  The main point, I guess is that you need to
create a recursive template in order to build the node list.

the xml:
<xml/>

the xsl:
<xsl:stylesheet  version="1.0"  xmlns:xsl
="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="xsl">

      <xsl:output method="xml" version="1.0" omit-xml-declaration = "yes"/>

	<xsl:template match="/">
		<xsl:call-template name="build-attribute-list">
			<xsl:with-param name="src-attribute-list">(name,Fred
Flintstone)(occupation,Excavation Engineer)</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

      <xsl:template name="build-attribute-list">
            <!--
                  Builds attribute-list.

                  Input:=
                     $attributeList =
'(att1Name,att1Value)(att2Name,att2Value)'

                  Output:=
                  <attribute-list>
                     <attribute name="att1Name" value="att1Value"/>
                     <attribute name="att2Name" value="att2Value"/>
                     ...
                  </attribute-list>
            -->

            <!-- src-attribute-list = '(n,v)(n,v)(n,v) ... ' -->
            <xsl:param name="src-attribute-list" />
            <xsl:element name="attribute-list" >
	       <xsl:if test="''!=$src-attribute-list">
                      <xsl:call-template name="__att-list-constructor">
                          <xsl:with-param name="attribute-list"
select="normalize-space($src-attribute-list)"/>
                     </xsl:call-template >
	       </xsl:if>
            </xsl:element>
      </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:attribute name="name"><xsl:value-of
select="normalize-space( substring-before($pair,',') )"/></xsl:attribute>
                     <xsl:attribute name="value" ><xsl:value-of
select="normalize-space( substring-after($pair,',') )"/></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>

</xsl:stylesheet>


the output:
<attribute-list>
<attribute name="name" value="Fred Flintstone" />
<attribute name="occupation" value="Excavation Engineer" />
</attribute-list>



hope this helps ...

-Jeff

-----Original Message-----
From: Alexandra Duda [mailto:oladuda@xxxxxxxxx]
Sent: Tuesday, December 04, 2001 6:33 AM
To: XSL-List@xxxxxxxxxxxxxxxxxxxxxx
Subject:  Convert string to a list of nodes


Hello all,

I have the following problem:
I have a template that should perform some action for a set of nodes. 
This set can contain a various number of elements, and each element is
unique within my XML document scope. This template looks moreless like this:
<xsl:template name="maintemplate">
  <xsl:param name="nodelist"></xsl:param>
  <!-- some other params -->

  <!--
   <![CDATA[
       here I want to proceed each node, that is listed in nodelist,
       something like <xsl:for-each> <xsl:call-template name="elemtempl">
       with some parameters.
      ]]> 
  -->
   
</xsl:template>

When I call this template, it should look like this:

<xsl:call-template name="maintemplate">
  <xsl:with-param name="nodelist">node1;node2;node3;node4</xsl:with-param>
   <!-- some params... -->
</xsl:call-template>

My question is: How can I convert the string from nodelist to set of nodes?
Or maybe there is another way to do, what I want to do, and my solution is
not the best way ? ;-)
Thanx for any help

ps.
my XML document looks moreless like this:
<elem1>
  <node1>value1</node1>
  <node2>value2</node2>
  <node3>value3</node3>
  ...
  <node7>
    <subnode1/>
    ...
  </node7>
</elem1>
...

Best regards,
Alexandra

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

 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.