This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: RE: Convert string to a list of nodes


Hello Jeff
Thanx for your email. 
Your code works fine. It is not exactly I need, but after a few modifications it should be ;-)
I have only one more question to you:
Is it possible to get a node, placed somewhere in my XML file during call to your template? I mean, if it is possible to call this template with for example (width,"")(height,"") nodelist (src-attribute-list) parameter and inside call a template that matches 'width' element from my XML file? (I know, that this element - like all other- is unique in my XML document scope).

Best regards
Alexandra

> 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">
>             <!--
&gt;                   Builds attribute-list.
&gt; 
&gt;                   Input:=
&gt;                      $attributeList =
&gt; '(att1Name,att1Value)(att2Name,att2Value)'
&gt; 
&gt;                   Output:=
&gt;                   <attribute-list>
&gt;                      <attribute name="att1Name" value="att1Value"/>
&gt;                      <attribute name="att2Name" value="att2Value"/>
&gt;                      ...
&gt;                   </attribute-list>
&gt;             -->
> 
>             <!-- 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
&gt; 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@poczta.fm]
> Sent: Tuesday, December 04, 2001 6:33 AM
> To: XSL-List@lists.mulberrytech.com
> Subject: [xsl] 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 -->
> 
>   <!--
&gt;    <![CDATA[
&gt;        here I want to proceed each node, that is listed in nodelist,
&gt;        something like <xsl:for-each> <xsl:call-template name="elemtempl">
&gt;        with some parameters.
&gt;       ]]> 
&gt;   -->
>    
> </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
> 
> 
> 

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]