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 November 13th, 2003, 01:04 AM
Registered User
 
Join Date: Nov 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:apply-templates - Pls help me out imme

Dear all
    Please help me imme in solving this.
I have some thing like this -
<tag1>
    ........
    ........
    <childtag1>ChildValue1</childtag1>
    <childtag1>ChildValue2</childtag1>
    <childtag1>ChildValue3</childtag1>
    .......
</tag1>

In the XSL, Iam using
    <xsl:template match='tag1'>
        <test1><xsl:apply-templates select="childtag1"></test1>
    </xsl:template>

The <xsl:apply-templates> element applies a template rule to the current

element or to the current element's child nodes.
So the output value (in the output xml) Iam getting is -
    <test1>ChildValue1ChildValue2ChildValue3</test1>
I want this output to be separated by commas, like
    <test1>ChildValue1, ChildValue2, ChildValue3</test1>.

How to achieve this?
Thx in advance.

-Avinash


***********************************

 
Old November 13th, 2003, 03:18 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 147
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to armmarti
Default

Hi,

I can suggest 2 approaches.

1) Add template rule for "childtag1":
Code:
<xsl:template match="childtag1">
 <xsl:value-of select="."/>
 <xsl:if test="following-sibling::childtag1">
  <xsl:text>,</xsl:text>
 </xsl:if>
</xsl:template>
2) or change the code you posted like this:
Code:
<xsl:template match='tag1'>
 <test1>
  <xsl:for-each select="childtag1">
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">
     <xsl:text>,</xsl:text>
    </xsl:if>
  </xsl:for-each>
 </test1>
</xsl:template>
Just for this example the second is more intuitive and readable and finally faster I think.

Regards,
Armen





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
xsl:apply-templates select problem harapraveen XSLT 2 October 22nd, 2007 08:05 AM
differnce between xsl:apply-templates and xsl:call chandu.mca007 XSLT 2 June 12th, 2007 04:12 AM
Doubt in XPATH synax in <xsl:apply-templates > rajatake XSLT 3 May 4th, 2006 06:30 AM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM





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