Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 23rd, 2009, 08:19 AM
Authorized User
 
Join Date: Sep 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 23rd, 2009, 08:33 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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, Data Platform Development) 2005/04 - 2013/03
My blog

Last edited by Martin Honnen; June 23rd, 2009 at 08:39 AM.. Reason: fixing code sample
 
Old June 23rd, 2009, 08:45 AM
Authorized User
 
Join Date: Sep 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 24th, 2009, 09:17 AM
Authorized User
 
Join Date: Sep 2008
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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.
 
Old June 24th, 2009, 09:29 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

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, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old June 24th, 2009, 01:54 PM
Friend of Wrox
 
Join Date: Jun 2007
Posts: 477
Thanks: 10
Thanked 19 Times in 18 Posts
Default

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.





Similar Threads
Thread Thread Starter Forum Replies Last Post
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
One query in xslt pasupathy.b XSLT 7 May 30th, 2007 05:53 PM
XSLT and Namspace Query. AjayLuthria XSLT 1 April 10th, 2007 11:57 AM
General Mail Merge Query iaingblack Word VBA 0 March 12th, 2007 05:01 PM
Query About XSLT-Urgent harshalchoksi XSLT 6 February 23rd, 2007 06:43 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.