SunQuest
           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:
SlickEdit: Code in over 40 languages across 7 platforms. SlickEdit’s unmatched power, speed, and flexibility allows even the most accomplished developers to write better code faster. Download a free trial today!
  #1  
Old August 4th, 2003, 09:08 AM
Tarzan Tarzan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Tarzan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Unhappy loop in xsl

Hi all,

Sorry for the lame question but I have no time to experiment (ugly deadlines, y'know).

I have a bunch of coordinates in an XML file like

<point x="1" y="1"/>
<point x="3" y="3"/>
<point x="5" y="0"/>

I need to create lines from the previous data like:

<line x1="1" y2="1" x2="3" y2="3"/>
<line x="3" y="3" x2="5" y2="0"/>

The only problem is that I cannot see the previous sibling node to have 2 pairs of coordinates at the same time. I've tried the following-sibling and preceding-sibling keywords but neither of them worked for me. If someone could help in this particular problem, I would be grateful...

Thanks,
Tarzan

Reply With Quote
  #2  
Old August 5th, 2003, 10:16 PM
chinnman chinnman is offline
Fries w/ That?
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Kansas
Posts: 8 chinnman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Howdy Tarzan-

How about not trying to loop it and just using apply-templates?

From your examp I made this xml:
<?xml version="1.0" encoding="UTF-8"?>
<mypoints>
<point x="1" y="1"/>
<point x="3" y="3"/>
<point x="5" y="0"/>
<point x="1" y="1"/>
<point x="3" y="3"/>
<point x="5" y="0"/>
</mypoints>

Then created this XSLT:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="mypoints">
<myNewTag>
<xsl:apply-templates/>
</myNewTag>
</xsl:template>
<xsl:template match="point">
<xsl:if test="following-sibling:oint/@x != &apos;&apos; ">
<line>
<xsl:attribute name="x">
<xsl:value-of select="@x"/>
</xsl:attribute>
<xsl:attribute name="y">
<xsl:value-of select="@y"/>
</xsl:attribute>
<xsl:attribute name="x2">
<xsl:value-of select="following-sibling:oint/@x"/>
</xsl:attribute>
<xsl:attribute name="y2">
<xsl:value-of select="following-sibling:oint/@y"/>
</xsl:attribute>
</line>
</xsl:if>
</xsl:template>
</xsl:stylesheet>

To get this output:
<?xml version="1.0" encoding="UTF-8"?>
<myNewTag>
<line x="1" y="1" x2="3" y2="3"/>
<line x="3" y="3" x2="5" y2="0"/>
<line x="5" y="0" x2="1" y2="1"/>
<line x="1" y="1" x2="3" y2="3"/>
<line x="3" y="3" x2="5" y2="0"/>
</myNewTag>

Hope this helps!!

Chinnman Out!!

Reply With Quote
  #3  
Old August 5th, 2003, 10:19 PM
chinnman chinnman is offline
Fries w/ That?
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2002
Location: Kansas
Posts: 8 chinnman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Sorry. Didn't disable smilies so replace all tongue waggers with ":P"

Thanks,
TCM!!

Reply With Quote
  #4  
Old August 6th, 2003, 03:21 AM
Tarzan Tarzan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Tarzan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
thanks

Thanks a lot, chinnman! It really helped me out! I've had problems with understanding the "sibling"-thing as the previous examples I found were kinda rocket science to me Unlike your sample was clear, thanks again!

Tarzan

Reply With Quote
  #5  
Old August 6th, 2003, 03:23 AM
Tarzan Tarzan is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2003
Posts: 3 Tarzan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Uhh, I meant: "Unlike your sample, that was clear." Sorry!

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > loop 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


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





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway