|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 != '' "><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!! |
|
#3
|
|||
|
|||
|
Sorry. Didn't disable smilies so replace all tongue waggers with ":P"
Thanks, TCM!! |
|
#4
|
|||
|
|||
|
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 |
|
#5
|
|||
|
|||
|
Uhh, I meant: "Unlike your sample, that was clear." Sorry!
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > loop in xsl |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|