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 January 8th, 2004, 12:11 AM
Culland Culland is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Culland User rank is Private First Class (20 - 50 Reputation Level)Culland User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 5
How can you access an attribute on the 'next' node with XSL?

I have something like the following for my xml:

<heading pos="3">
...
</heading>
<heading pos="30">
...
</heading>
<heading pos="300">
...
</heading>

When doing my XSL I am building a href at a heading that includes the start pos and the end pos using the pos attribute in each heading. So and output from XSLT might look like:

<a href="somepage.html?startpos=3&endpos=30">...</a>
<a href="somepage.html?startpos=30&endpos=300">...</a>

I can build the href fine, I can add the startpos fine, but I am not sure how to get the attribute of the next node in order to create endpos? I thought of storing the startpos in a parameter and then getting it when I get to the next node, but unfortunetly I need to process other elements before the end of the heading and I want them after the href.

Thoughts?

Cul

Reply With Quote
  #2  
Old January 8th, 2004, 12:30 PM
Culland Culland is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Culland User rank is Private First Class (20 - 50 Reputation Level)Culland User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 5
Ok I have almost figured it out, I have the following:

<a href="mypage.php?startpos={attribute:os}endpos={following-sibling::*/attribute:os}

Works great other then its not a valid url as endpos needs a & in front of it. Including it breaks the transform every time. I tried escaping it out, but still no luck. Any ideas on how I can include the '&'?

Cul

Reply With Quote
  #3  
Old January 8th, 2004, 12:42 PM
Culland Culland is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Culland User rank is Private First Class (20 - 50 Reputation Level)Culland User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 5
Ok got it work, yay!


<a href="mypage.php?startpos={attributes}&endpos={following-sibling::*/attributes}

Cul

Reply With Quote
  #4  
Old January 8th, 2004, 12:57 PM
Culland Culland is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Culland User rank is Private First Class (20 - 50 Reputation Level)Culland User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 5
Sorry forgot to disable smilies.

<a href="mypage.php?startpos={attribute::pos}&endpos={following-sibling::*/attribute:pos}

I still need to put a check in there so that if there is no sibling to provide the endpos value to get it from another spot. Any thoughts?

Cul

Reply With Quote
  #5  
Old January 8th, 2004, 01:37 PM
Culland Culland is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2003
Posts: 38 Culland User rank is Private First Class (20 - 50 Reputation Level)Culland User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 55 m 6 sec
Reputation Power: 5
While I know I am largely talking to myself I thought I would put the last of my additions just in case anyone ever searches for this topic :)

I ended up with:

<xsl:choose>
<xsl:when test="following-sibling::*">
<a href="mypage.php?startpos={attribute::pos}&endpos={following-sibling::*/attribute:pos}
</xsl:when>
<xsl:otherwise>
<a href="mypage.php?startpos={attribute::pos}&endpos={parent::*/following-sibling::*/attribute:pos}
</xsl:otherwise>
</xsl:choose>

Well thats the short version of what I ended up with, there is a bit more to handle when there is no sibling on the parent as well, but that gives the general point.

Cul

Reply With Quote
  #6  
Old January 8th, 2004, 01:59 PM
imbrokn imbrokn is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2001
Location: NJ
Posts: 428 imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level)imbrokn User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 11 h 34 m 8 sec
Reputation Power: 10
Send a message via AIM to imbrokn
Good Job figuring it out, and thanks for posting the solution. Many times, I've read posts where people will respond to there own post just saying something llike "Forget it guys, I figured it out" without leaving a solution. Anyway, I was gonna help but obviously you figured it out. But for future reference and anyone who might stumble accross this, if you are looking for the previous sibling, as opposed to the next one you would do something like this:

{preceding-sibling::heading[1]/@pos}

I was a little bit confused about how this and why the [1] was necessary, but it won't work without it. This little post has some information why, which kind of clears things up, but not really well enough for me to explain.

http://www.xslt.com/xsl-list/2002-06/msg00026.html

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > How can you access an attribute on the 'next' node with 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 2 hosted by Hostway