This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Convert string to a list of nodes
- From: Jeff Beadle <Jbeadle at manh dot com>
- To: xsl-list at lists dot mulberrytech dot com
- Date: Tue, 4 Dec 2001 08:54:58 -0500
- Subject: RE: [xsl] Convert string to a list of nodes
- Reply-to: xsl-list at lists dot mulberrytech dot com
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@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 -->
<!--
<![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