XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 21st, 2004, 01:32 PM
pgudge pgudge is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2001
Location: South Yorkshire
Posts: 436 pgudge User rank is Sergeant (500 - 2000 Reputation Level)pgudge User rank is Sergeant (500 - 2000 Reputation Level)pgudge User rank is Sergeant (500 - 2000 Reputation Level)pgudge User rank is Sergeant (500 - 2000 Reputation Level)pgudge User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 5 h 13 m 52 sec
Reputation Power: 18
loop function in XSL?

If I have the following tags in XML:

Code:
<DIR name="files">
  <FILE name="hello.txt">
  <FILE name="hello.bat">
  <DIR name="HELP">
    <FILE name="README.TXT"/>
    <FILE name="help.hlp"/>
  </DIR>
</DIR>
<DIR name="images">
  <FILE name="logo.gif"/>
</DIR>


So 2 directories off root "files" and "images", the files dir has 2 files and another dir.

When I do my XSL like this:

Code:
<xsl:template match="DIR">
  DIR: <xsl:value-of select="@name"/><BR/>
  FILES:<BR/>
  <xsl:for-each select="FILE">
    <xsl:value-of select="@name"/><BR/>
  </xsl:for-each>
</xsl:template>

I only get the FILE tags, But I want both like a explorer view, so I put "*" instead of "FILE" this does all <DIR> and <FILE> inside the top <DIR>

great.

But the <DIR> tag inside the top<DIR> tag gets renders here, and shows as a file, and I want the whole <DIR> code to start again for this object.

Is that possible?

Thanks.
__________________
regards,

pgudge

Reply With Quote
  #2  
Old June 21st, 2004, 07:00 PM
jharnois's Avatar
jharnois jharnois is offline
mod_dev_shed
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Sep 2002
Location: Atlanta, GA
Posts: 14,569 jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level)jharnois User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 1 Week 2 Days 22 h 42 m 51 sec
Reputation Power: 835
I like to provide working code in my replies, but this is all theory (meaning I've never done something like this exactly), and I just don't have time to test and tweak to get a working example. But, here's what I would try doing ... create a template to handle the FILEs. You can then call this template using apply-templates. In this template, you will have to use an "if" to determine if the tag is a FILE or a DIR and then apply-templates again. So you'll apply-templates recursively like you might have a recursive function in a programming language. You might have to get real tricky here, using current(), node(), or any other function available. W3 Schools is a good place to get some quick examples and a list of functions.
__________________
# Jeremy

Explain your problem instead of asking how to do what you decided was the solution.

Reply With Quote
  #3  
Old June 22nd, 2004, 03:02 AM
kid23 kid23 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 62 kid23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
You don't even need a loop:

Code:
<xsl:template match="DIR">
  DIR: <xsl:value-of select="@name"/><BR/>
  <xsl:if test="count(FILE) != 0">
    FILES:
  </xsl:if>
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="FILE">
  <xsl:value-of select="@name"/><BR/>
</xsl:template>


I haven't tested the code (not enough time), but basically, what you are doing is:

DIR:
- write the name of the directory
- test if the number of FILE tags is different than 0, and if so, write "FILES:"
- apply-templates

apply-templates means that XSLT will apply whatever template is necessary, based on what your XML contains. If it finds a DIR tag, it will use the DIR template, if it finds a FILE tag, it will use the FILE template.

Hope this helps

Reply With Quote
  #4  
Old June 22nd, 2004, 10:09 AM
Teflon's Avatar
Teflon Teflon is offline
Teflon The Black
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Woodbridge VA
Posts: 246 Teflon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 14 sec
Reputation Power: 5
Send a message via AIM to Teflon
have you looked into <xsl:for-each select='DIV'>

? you could get this to work say for every div you get print out a / and a break and then a tab ?

-Teflon
__________________
Teflon - The Black <desc>Mark This Up</desc>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > loop function in XSL?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT