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 August 26th, 2004, 01:38 AM
Phrenetical Phrenetical is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 156 Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 5 sec
Reputation Power: 9
Talking Reversing XML readout (upside down upside down)

Ok what im wondering is, is there a way to make your XSL print out your xhtml/xml from the last entry to the first entry, so the output on the webpage, is

1. = last entry
2. = 2nd last entry
..
..
..
..
50. = first entry

because normally if you use for:each in your xsl to output your xml, it will do it from the first xml entry to the last xml entry

all i wanna do is reverse it


example xml

Code:
<main>
   <entry 1> 
      <tags>Print me last</tags>
   </entry 1>
   <entry 2>
      <tags>Print me second</tags> 
   </entry 2>
   <entry 3> 
      <tags>Print me first</tags> 
   </entry 3>
</main>


so normally a for:each xsl statement will print out your xml like

1. Print me last
2. Print me second
3. Print me first

i want it to print out like this

1. Print me first
2. Print me second
3. Print me last

I wanna do this for more than 3 xml entries, so no one give me dodgy solutions of switching the first and last entry only.

Reply With Quote
  #2  
Old August 26th, 2004, 02:56 PM
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
it's just a quick suggestion, untested, and absolutely not sure it's possible, but if you could always have a look at the xpath functions that allow you to work on the last node in a given context:

/main/entry[last()]

then use a loop to get the preceding siblings one by one, by using preceding-sibling::

Refer to xpath tutorials if you're not familiar with these. Sorry I can't provide you with a full solution atm, but if you go into that direction, you should be able to get results.

good luck.

Btw, if you make progress on your own and get stuck at some point, post it, i'll try to provide further assistance

Reply With Quote
  #3  
Old August 26th, 2004, 07:27 PM
Phrenetical Phrenetical is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 156 Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 5 sec
Reputation Power: 9
WIll look into xpaths, shouldnt be that difficult, and the results will be worth it.

If i get stuck i will defenently enlist your help man, then we can market our solution.

Reply With Quote
  #4  
Old August 26th, 2004, 08:21 PM
Phrenetical Phrenetical is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 156 Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 5 sec
Reputation Power: 9
Ok i might try this, and see how it works on weekend, im at work now


XML

Code:
<tag lineNo="1">
<tag lineNo="2"> 
<tag lineNo="3"> 
<tag lineNo="4">  


My XSL

Code:
<xsl:for-each select = "./tag">
<xsl:sort select="@lineNo" order="descending" 
data-type="number"/>
<xsl:number value = "./@lineNo" format="1."/>
<xsl:value-of select ="."/>
</xsl:for-each>



I dont know if it it will work, but it may be a better option than xpaths, its relatively simple to, just a pain to add lineNo all the time. then again its perl output so it wont be that bad.

Reply With Quote
  #5  
Old August 27th, 2004, 03:06 PM
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
found some time to dig into it:

xml:
Code:
<main>
   <entry> 
      <tags>Print me 5th</tags>
   </entry>
   <entry> 
      <tags>Print me 4th</tags>
   </entry>
   <entry> 
      <tags>Print me 3rd</tags>
   </entry>
   <entry>
      <tags>Print me 2nd</tags> 
   </entry>
   <entry> 
      <tags>Print me 1st</tags> 
   </entry>
</main>


xsl:
Code:
<xsl:template match="main">
  <html>
    <body>
      <xsl:apply-templates select="/main/entry[last()]" />
    </body>
  </html>
</xsl:template>

<xsl:template match="entry">
  <xsl:value-of select="tags"/>
  <br />
  <xsl:apply-templates select="preceding-sibling::entry[1]" />
</xsl:template>


output:
Code:
Print me 1st
Print me 2nd
Print me 3rd
Print me 4th
Print me 5th


Initial apply-templates positions you on the very last entry tag, then within the entry template, you apply-templates again by specifying that you want the entry tag that is IMMEDIATELY preceding the current one, this is done by using
preceding-sibling::entry[1], using it without the [1] didn't work.


Reply With Quote
  #6  
Old August 29th, 2004, 07:11 PM
Phrenetical Phrenetical is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 2004
Posts: 156 Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level)Phrenetical User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 1 Day 5 sec
Reputation Power: 9
Im definently gonna try that one out, the one i posted was hell buggy.

It will be interesting to see if i can get your code to display, in line with my other post about two columns of XML,

thanks again.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Reversing XML readout (upside down upside down)


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
Stay green...Green IT