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

RE: Comma delimited parameters...

Subject: RE: Comma delimited parameters...
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Tue, 18 Sep 2001 18:03:57 +0100
vbscript comma delimited
You need to write a recursive named template to split the parameter string.
The general structure is

template name="split"
  param name="list"
  variable name="first" select="substring-before($list, ',')"
  variable name="rest" select="substring-after($list, ',')"
  (process $first)
  if test="$rest"
    call-template name="split"
      with-param name="list" select="$rest"
    /call-template
  /if
/template

Alternatively, use the saxon:tokenize() or xalan:tokenize() extension
functions.

Mike Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Casadome,
> Francisco Javier
> Sent: 18 September 2001 15:11
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  Comma delimited parameters...
>
>
> Hi all,
>
> I have an XSL receiving parameter that is a list of names separated by
> commas, like this:
> name1,name2,name3,name4,name5,name6,
> (note that the last one also have a comma at the end)
>
> Then I have a XML file with nodes that may or may not have
> these names as
> childs, like this:
>
> <myXML>
> 	<node1>
> 		<name1>XXX</name1>
> 		<name3>CCC</name3>
> 	</node1>
> 	<node2/>
> 	<node3>
> 		<name3>AAA</name3>
> 		<name6>QQQ</name6>
> 	</node3>
> </myXML>
>
> What I want to do is to create a TAB-separated file with all
> the names in
> the parameter as the first line, like this:
>
> -----------------------------------
> name1	name2	name3	name4	name5	name6
> -----------------------------------
> XXX		CCC
>
> 		AAA			QQQ
> -----------------------------------
>
> This is the XSL I have right now:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="text" omit-xml-declaration="yes" indent="no"/>
> <xsl:param name="Fields"/>
>
> 	<xsl:key name="AllPossibleFields" match="Entry/*" use="name()"/>
>
> 	<xsl:template match="Entries">
> 		<xsl:apply-templates select="Entry/*[count(. |
> key('AllPossibleFields',name())[1]) = 1]"/>
> 		<xsl:text>&#013;&#010;</xsl:text>
> 		<xsl:for-each select="Entry">
> 			<xsl:for-each select="*">
> 				<xsl:if
> test="contains($Fields,concat(name(),','))">
> 					<xsl:value-of
> select="."/><xsl:text>&#009;</xsl:text>
> 				</xsl:if>
> 			</xsl:for-each>
> 			<xsl:text>&#013;&#010;</xsl:text>
> 		</xsl:for-each>
> 	</xsl:template>
>
> 	<xsl:template match="*">
> 		<xsl:if test="contains($Fields,concat(name(),','))">
> 			<xsl:value-of
> select="name()"/><xsl:text>&#009;</xsl:text>
> 		</xsl:if>
> 	</xsl:template>
>
> </xsl:stylesheet>
>
> Here you can see that what I do is to check if the current
> node plus a comma
> is in the parameter list using the contains() function. I do
> this because I
> don't know how to split this string without using an embed VBScript.
> Also, I don't get name2, name4 and name5 in the header row,
> because there
> isn't any node with such childs.
>
> Any great ideas ?
>
> Thanks in advance,
> Frank.
>
>  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.