|
|
 |
| XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XSLT section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |
|

June 23rd, 2009, 09:19 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
OK here are some inputs and outputs expected. I hope this will help?
INPUTS
This will be from the sitemap xml but assume the input for one level will be:
Code:
<sitemap>
<navlink>
<description>some link one</description>
<linktarget>http//www.linkone.com</linktarget>
</navlink>
<navlink>
<description>some link two</description>
<linktarget>http//www.linkone.com</linktarget>
</navlink>
<navlink>
<description>some link three</description>
<linktarget>http//www.linkone.com</linktarget>
</navlink>
</sitemap>
OUTPUT
The output will simply just show the <description> as a hyperlink to <linktarget>.
I would like to loop through the sitemap xml and check the current page is the same as (x) in the sitemap loop. If it is the same, check to see if (x) is not the last link. If it is not, then display the next description and linktarget as the hyperlink. If it is the last link, simply do nothing or just output some generic text such as "last".
Does this help?
Trying to explain best I can.
|

June 23rd, 2009, 09:33 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
|
|
XSLT does not have a concept of a page or current page, it processes XML input and transforms it to HTML or XML or plain text output.
If the environment you use XSLT with does have a concept of a current page then define a global parameter in your XSLT stylesheet that you can then set before the transformation to pass in the current page.
Then in your stylesheet you can check
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="cp"/>
<xsl:variable name="np" select="/sitemap/navlink[linktarget = $cp]/following-sibling::navlink[1]"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$np">
<a href="{$np/linktarget}">
<xsl:value-of select="$np/description"/>
</a>
</xsl:when>
<xsl:otherwise>last</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP - XML
My blog
Last edited by Martin Honnen : June 23rd, 2009 at 09:39 AM.
Reason: fixing code sample
|

June 23rd, 2009, 09:45 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Blimey, that was a speedy reply. I will certainly give that a try and let you know if that works.
Regarding your concept of the a currentpage, the environment I use must have this as this is what it uses to get the current page value:
Code:
<xsl:variable name="currPage">
<xsl:value-of select="/Properties/Data/Result/page_info/@pagename" />
</xsl:variable>
This code is quite alien to me. I hope I can put your code example to good use.
Thank you again for taking the time to provide help. You truly are an expert.
|

June 24th, 2009, 10:17 AM
|
|
Authorized User
|
|
Join Date: Sep 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi
Many thanks for your help but I am still struggling (just a little) with the code you supplied. I have learnt a lot from this so far.
Would it be possible to help me a little more as I have now got the true inputs used and its the link value property i'm struggling with (syntax). Here is the input to use:
Code:
<segment>
<node id="fr7xrxbb" allow-children="true" visible-in-sitemap="true">
<label key="">click here</label>
<description />
<link type="page" target="">
<value>about_us/media_centre/index</value>
<query-string preserve-qs-data="false" />
</link>
<aliases />
</node>
</segment>
Almost there now and thank you again.
|

June 24th, 2009, 10:29 AM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
|
|
What is it exactly that you want to do with that input?
Assuming you want to check the value child element of your link element against the parameter you have then you simply need to adapt the XPaths:
Code:
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:param name="cp"/>
<xsl:variable name="np" select="/segment/node[link/value = $cp]/following-sibling::node[1]"/>
<xsl:template match="/">
<xsl:choose>
<xsl:when test="$np">
<a href="{$np/link/value}">
<xsl:value-of select="$np/description"/>
</a>
</xsl:when>
<xsl:otherwise>last</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP - XML
My blog
|

June 24th, 2009, 02:54 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 278
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
I'm confused why you don't have access to the "real" XML, is it encrypted? Or do you lack sufficient rights to its location?
As Michael said, XSLT is just about transforming one file into another. If you don't have access to the code, there's no way you can do this job. Have the administrator who whoever has access to the information post for assistance. It sounds like there's some fundamental confusion about how XSLT works. Whoever has access to the XML is the person who HAS to write the XSLT.
__________________
-------------------------
Whatever you can do or dream you can, begin it. Boldness has genius, power and magic in it. Begin it now.
-Johann von Goethe
When Two Hearts Race... Both Win.
-Dove Chocolate Wrapper
Chroniclemaster1, Founder of www.EarthChronicle.com
A Growing History of our Planet, by our Planet, for our Planet.
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |