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 April 30th, 2010, 04:20 PM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Default Help with XSL/XML

Hi,

I am a beginner to XSL/XML. I may not be using proper terms in describing my question. Please excuse.

I have a XML file which looks like below -

Code:
	<Emp>
		<SSN>xxx-xx-xxxx</SSN>
		<Name>ABC</Name>
		<Phone>6507231234</Phone>
		<Phone>6507553223</Phone>
	</Emp>
        <Emp>
		<SSN>xxx-xx-xxxy</SSN>
		<Name>BCD</Name>
		<Phone>6507231235</Phone>
		<Phone>6507553226</Phone>
	</Emp>
I have written a XSL file to display the data in XML onto HTML. Part of the code looks like as shown below -

Code:
  <table>
      <tr>
        <th>SSN</th>
        <th>Name</th>
        <th>Phone</th>
      </tr>
      <xsl:for-each select="Emp">
        <tr>
          <td><xsl:value-of select="SSN"/></td>
          <td><xsl:value-of select="Name"/></td>
          <td><xsl:value-of select="Phone"/></td>
        </tr>
      </xsl:for-each>
    </table>
The above code displays just the first value of Phone. How should I modify the code to display the multiple values
 
Old April 30th, 2010, 04:34 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Simply use another for-each loop:

Code:
<xsl:for-each select="Phone">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
learnxsl (April 30th, 2010)
 
Old April 30th, 2010, 04:43 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In fact, this is an area where XSLT 2.0 differs from 1.0: in XSLT 2.0 (if your stylesheet specifies version="2.0", the code you supplied <xsl:value-of select="Phone"/> will output all the phone numbers, space separated; if you want a different separator, you can use <xsl:value-of select="Phone" separator=","/>. In XSLT 1.0, however, you need another xsl:for-each loop.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
learnxsl (April 30th, 2010)
 
Old April 30th, 2010, 04:53 PM
Registered User
 
Join Date: Apr 2010
Posts: 2
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Interesting to know about this difference between Version 1.0 and 2.0.

Had I created XSLT 2.0, my code would have worked and I would not have known the difference. Nice learning.

Thanks to all.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
Transforming XML to XML using XSL sakreck XSLT 0 January 9th, 2007 11:48 AM
XML To XML, using XSL & XSD supercop75 XSLT 1 April 8th, 2006 02:48 AM
xml and xsl templates as input to xslt gives xml rameshnarayan XSLT 5 August 3rd, 2005 01:58 AM
Is it my XML or XSL or none of the above ryanpatrick XML 16 May 31st, 2005 09:22 AM





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