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 October 22nd, 2007, 06:21 AM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:apply-templates select problem

Hello,
i have one problem using xsl:apply-templates select=""

i have an xml

<ROOT>
  <AUTHOR>AU1</AUTHOR>
  <AUTHOR>AU2</AUTHOR>
  <AUTHOR>AU3</AUTHOR>
  <AUTHOR>AU4</AUTHOR>
  <AUTHOR>AU5</AUTHOR>
</ROOT>

my xslt code is:
<fo:block>
AUTHOR: <xsl:apply-templates select="AUTHOR"/>
</fo:block>


the output i want is like this
AUTHOR:AU1,AU2,AU3,AU4,AU5

but i output i get is
AUTHOR:AU1AU2AU3AU4AU5

Can any one help me, how can i get comma separated output.

Thank you



 
Old October 22nd, 2007, 06:55 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

AUTHOR:
  <xsl:for-each select="AUTHOR">
    <xsl:apply-templates select="."/>
    <xsl:if test="position() != last()">,</xsl:if>
  </xsl:for-each>

Alternatively you can put the same <xsl:if> instruction inside the match="AUTHOR" template.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old October 22nd, 2007, 08:05 AM
Registered User
 
Join Date: Jan 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you
This worked

Quote:
quote:Originally posted by mhkay
 AUTHOR:
  <xsl:for-each select="AUTHOR">
    <xsl:apply-templates select="."/>
    <xsl:if test="position() != last()">,</xsl:if>
  </xsl:for-each>

Alternatively you can put the same <xsl:if> instruction inside the match="AUTHOR" template.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:param and xsl:apply-templates' "select" newbieboobers XSLT 1 March 25th, 2008 07:23 PM
odd error with apply-templates select="..." name Fitty XSLT 1 January 18th, 2008 03:45 AM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM
xsl:apply-templates - Pls help me out imme Avinash XSLT 1 November 13th, 2003 03:18 AM





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