|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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 |
|
#3
|
|||
|
|||
|
Ok got it work, yay!
<a href="mypage.php?startpos={attribute s}&endpos={following-sibling::*/attribute s}Cul |
|
#4
|
|||
|
|||
|
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 |
|
#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 |
|
#6
|
|||
|
|||
|
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 |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > How can you access an attribute on the 'next' node with XSL? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|