473,770 Members | 2,069 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

xslt looping help :-( please

1 New Member
Hi!

Ok so im having a very very rookie (i assume) problem.

I want to take this:
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <?xml-stylesheet type="text/xsl" href="xslTest.xsl"?>
  3. <dataTree>
  4.  
  5.     <group>
  6.         <teacher>John Jacobs</teacher>
  7.              <classr>Algebra I</classr>
  8.              <classr>Algebra II</classr>
  9.     </group>
  10.  
  11.  
  12.     <group>        
  13.         <teacher>Goldberg</teacher>
  14.              <classr>History I</classr>
  15.              <classr>History II</classr>
  16.     </group>  
  17.  
  18. </dataTree>
  19.  
and turn it into this:

Expand|Select|Wrap|Line Numbers
  1. John Jacobs
  2.  
  3. Algebra I
  4. Algebra II
  5.  
  6. Goldberg
  7.  
  8. History I
  9. History II
  10.  

This is what i thought would work:


Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="ISO-8859-1"?>
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4.  
  5. <xsl:template match="/">
  6.  <html>
  7.  <body>
  8.  
  9.  <xsl:for-each select="dataTree/group">
  10.             <xsl:value-of select="teacher" /><br /><br />
  11.             <xsl:value-of select="classr" /><br />            
  12.  </xsl:for-each>
  13.  
  14.  </body>
  15.  </html>
  16. </xsl:template>
  17. </xsl:stylesheet>
  18.  
this is what i get:

Expand|Select|Wrap|Line Numbers
  1. John Jacobs
  2.  
  3. Algebra I
  4. Goldberg
  5.  
  6. History I
  7.  
I just learned XSLT last night but i know java and javascript and php and C# and all of those languages so I thought this would work. can anyone suggest another way or point out what im doing wrong?

thank you soo much!
Jul 26 '07 #1
1 1199
jkmyoung
2,057 Recognized Expert Top Contributor
there are multiple classr nodes; you need another for-each. Where you have:
<xsl:value-of select="classr" /><br />
Replace with
<xsl:for-each select="classr" ><xsl:value-of select="."/><br/></xsl:for-each>
Jul 27 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

5
2228
by: Ruthless | last post by:
hello. All XML and XSLT are processed by preprocessor as a trees. How can i simply display my XML as some kind of tree. given xml: <struct> <node level="1" no="1">
3
1676
by: Just Curious | last post by:
Hello, I have a following situation.. XML Document contains <PurchaseOrder> <LineItems> <LineItem> <Description></Description> </LineItem> <LineItem>
3
2350
by: Michael Ahlers | last post by:
Obviously if you're looping or using a template, choosing output based on the current iteration is easy. For example, if you're walking a set of elements and you want index % 2 == 0 produce one thing and another when that is not true. My question is, what if you are not looping through tags but want to achieve a similar effect without having to be excessively verbose? Is there any way that I can simplify the following block? <!-- ......
3
2197
by: Teksure | last post by:
Hi group, searching in the Internet I found two products for XML which incorporate a very robust debugger for XSL/XSLT, I would like you to see these products and then, give me your opinion about the development environment or recommend me some other that you know. XML IDE's - http://xslt-process.sourceforge.net - http://www.mentattech.com/themes/mentat/alchemist/index.html Regards,
6
3237
by: Christopher | last post by:
I am currently in the process of evaluating the performance hits of moving to the .NET platform for our application. I created a sample project that loads the transforms the same XML and XSLT in COM, COM using interop and in C# and then transforms it to HTML. I also tried concatenating the XML and XSL as a string and then loading it to the DOM once as opposed to loading the DOM with the appendChild() method. I see that the C# version is...
4
2211
by: Iain | last post by:
Hi all, I am try to split the some data out of a nested xml file and get all the data in one new xml file. I have two XSLT files one takes the personal information and one takes the data out of the fund section , then I import each xml files into the datebase and do I relationship between the two. This is not what my boss wants as he wants one xml file This is my current XML
6
3014
by: aidy | last post by:
Hi, This is a snippet of my XSLT <xsl:for-each select = "SAFS_LOG/LOG_MESSAGE"> <xsl:choose> <xsl:when test="@type = 'FAILED'"> <xsl:variable name="isFailed" select="@type" /> <BR> "FAILED" </BR> </xsl:when>
1
4747
by: balderdash | last post by:
Hi I am very close to achieving the output I need but I cant seem to get it right. The problem is I am looping through a table and selecting values, if there are 2 values per (row) Issuer I need to put a slash between them in the output xml. The problem is shown by the output at the bottom of this post. I am
8
3458
by: Lawrence | last post by:
Hi Is there any way of using variables in XSLT? I have been using <xsl:param name="showDetails"/and want to be able to set it to say 1 or 0 dependent on certain XSL:if statements throughout...is this possible? Kind Regards Lawrence
0
9618
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10101
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9906
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5482
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3609
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.