Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 17th, 2006, 01:38 PM
Registered User
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default Passing multiple arguments to function

Is it possible to transform from:

<root>
<element>
<info>
<name>Name</name>
</info>
<links>
<child>A</child>
<child>B</child>
<child>C</child>
<child>D</child>
</links>
</element>
</root>

to the following form?

<td onclick="function(A,B,C,D)">Name</td>

Where it doesn't necessarily have to have 4 children (i.e. could have any variable number of children).

Thank you so much!
 
Old July 17th, 2006, 06:58 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Sure. Assuming <element> is the context node:

In XSLT 2.0:

<td onclick="function({string-join(links/*, ','})">
  <xsl:value-of select="info/name"/>
</td>

In XSLT 1.0:

<td>
  <xsl:attribute name="onclick">
    <xsl:text>function(</xsl:text>
    <xsl:for-each select="links/*">
      <xsl:value-of select="."/>
      <xsl:if test="position()!=last()">,</xsl:if>
    </xsl:for-each>
    <xsl:text>)</xsl:text>
  </xsl:attribute>
  <xsl:value-of select="info/name"/>
</td>



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 18th, 2006, 09:35 AM
Registered User
 
Join Date: Jun 2006
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Declarative arguments passing between DetailsViews andremi Classic ASP Basics 1 May 10th, 2007 09:24 PM
passing arguments to executables DaveG BOOK: Professional SQL Server 2005 Integration Services ISBN: 0-7645-8435-9 0 May 30th, 2006 03:26 PM
Problem passing multiple arguments to php script method PHP How-To 0 February 8th, 2006 09:03 AM
Passing arguments to contructor of dynamically... jacob ASP.NET 1.0 and 1.1 Professional 3 December 2nd, 2005 02:43 PM
passing/getting arguments from ShellExecute TazMania23 Visual C++ 0 May 21st, 2004 12:14 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.