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

Re: list of Values

Subject: Re: list of Values
From: David Tolpin <dvd@xxxxxxxxxxxxxx>
Date: Thu, 27 Nov 2003 23:18:28 +0400 (AMT)
xsl param list
[ Charset ISO-8859-1 unsupported, converting... ]
> Hi,
> How can I create a list of values?
> 
> I want select n values from the xml file and put them in one list
> to pass with-param to one template, something like this:
> 
> <xsl:call-template name="tempName">
>     <xsl:with-param name="$paramName" select="$listValues"/>
> 
> </xsl:call-template>
> 
> where listValue have for exemple the elements 'a' , 'b', 'c', 'd'
> 
> after that I want  shift paramName to use each of these values...

If the values are present in the source XML file, then to accumulate 
the values in a data structure one can use node-set union operation.

One can later iterate (for-each) through the node-set or pass and increment
position in the node-set as a parameter for the template.

For example, the simple stylesheet below uses node-set 
to implement a grouping algorithm.

<xsl:transform 
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	version="1.0">

  <xsl:template name="group-n">

    <xsl:param name="e" select="."/>
    <xsl:param name="es" select="."/>
    <xsl:param name="i">1</xsl:param>
    <xsl:param name="n"/>
    <xsl:param name="group">group</xsl:param>

    <xsl:variable name="enext" select="$e/following-sibling::*[1]"/>

    <xsl:choose>
      <xsl:when test="$i = $n">
	<xsl:element name="{$group}">
	  <xsl:apply-templates select="$e|$es"/>
	</xsl:element>
	<xsl:for-each select="$enext">
	  <xsl:call-template name="group-n">
	    <xsl:with-param name="group" select="$group"/>
	    <xsl:with-param name="n" select="$n"/>
	  </xsl:call-template>
	</xsl:for-each>
      </xsl:when>
      <xsl:otherwise>
	<xsl:call-template name="group-n">
	  <xsl:with-param name="group" select="$group"/>
	  <xsl:with-param name="i" select="$i+1"/>
	  <xsl:with-param name="n" select="$n"/>
	  <xsl:with-param name="e" select="$enext"/>
	  <xsl:with-param name="es" select="$es|$enext"/>
	</xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>

  </xsl:template>

</xsl:transform>


 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.