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 2nd, 2004, 10:04 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to saurabh0
Default XSLT: unexpected result

I am trying to transform this:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="b.xsl"?>
<aa>
   <bb>111</bb>
   <bb>222</bb>
   <bb>333</bb>
</aa>
Using this xsl:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
      <xsl:for-each select="aa">
        <xsl:value-of select="bb"/><br/>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>
and I am getting this output:
Code:
111
Whereas I was expecting:
Code:
111
222
333
Where am I going wrong ?

 
Old November 2nd, 2004, 10:38 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

First you loop over all the aa elements, there's only one and can never be more as then your XML would be malformed. You then ask for the value of all the bb elements. In XSLT 1 the value is the string value of the first node. You either want:
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <xsl:for-each select="aa/bb">
      <xsl:value-of select="."/><br/>
    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
or
Code:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="bb">
    <xsl:value-of select="."/><br/>
  </xsl:template>
</xsl:stylesheet>
--

Joe (Co-author Beginning XML, 3rd edition)
 
Old November 2nd, 2004, 11:45 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to saurabh0
Default

It worked, thanks a lot! :D

 
Old November 2nd, 2004, 11:47 AM
Registered User
 
Join Date: Nov 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to saurabh0
Default

I want to learn XSLT, could you recommend me a book ?

 
Old November 2nd, 2004, 01:21 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well in some ways it's a bad time to learn from books as the new specification is out for version 2 but not many processors support it. Anything by Michael Kay will be good, your best bet is probably his latest work XSLT 2.0 Programmer's Reference, 3rd Edition.
It has all the new stuff but also indicates what is new so you can just use version one if you need to.
The original edition is where I learned from.




--

Joe (Co-author Beginning XML, 3rd edition)





Similar Threads
Thread Thread Starter Forum Replies Last Post
GridView and SQL More than one result = one result DarkForce ASP.NET 2.0 Basics 0 July 20th, 2007 04:29 AM
Transforming a result tree with yet another Xslt ballo XSLT 2 March 7th, 2006 09:42 AM
Simple XSLT Setup w/Strange Result kwilliams XSLT 5 August 5th, 2005 11:47 AM
Unexpected T_VARIABLE deamato BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 February 26th, 2005 08:11 PM
Unexpected result from the query tsimsha Classic ASP Databases 1 August 23rd, 2004 03:50 AM





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