p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #11 (permalink)  
Old June 23rd, 2009, 09:19 AM
Authorized User
Points: 49, Level: 1
Points: 49, Level: 1 Points: 49, Level: 1 Points: 49, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: , , .
Posts: 12
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #12 (permalink)  
Old June 23rd, 2009, 09:33 AM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 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
My blog

Last edited by Martin Honnen : June 23rd, 2009 at 09:39 AM. Reason: fixing code sample
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #13 (permalink)  
Old June 23rd, 2009, 09:45 AM
Authorized User
Points: 49, Level: 1
Points: 49, Level: 1 Points: 49, Level: 1 Points: 49, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: , , .
Posts: 12
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #14 (permalink)  
Old June 24th, 2009, 10:17 AM
Authorized User
Points: 49, Level: 1
Points: 49, Level: 1 Points: 49, Level: 1 Points: 49, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2008
Location: , , .
Posts: 12
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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #15 (permalink)  
Old June 24th, 2009, 10:29 AM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 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
My blog
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #16 (permalink)  
Old June 24th, 2009, 02:54 PM
Friend of Wrox
Points: 941, Level: 11
Points: 941, Level: 11 Points: 941, Level: 11 Points: 941, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2007
Location: San Diego, CA, USA.
Posts: 278
Thanks: 0
Thanked 4 Times in 4 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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

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 08:50 PM
One query in xslt pasupathy.b XSLT 7 May 30th, 2007 06:53 PM
XSLT and Namspace Query. AjayLuthria XSLT 1 April 10th, 2007 12:57 PM
General Mail Merge Query iaingblack Word VBA 0 March 12th, 2007 06:01 PM
Query About XSLT-Urgent harshalchoksi XSLT 6 February 23rd, 2007 06:43 AM



All times are GMT -4. The time now is 02:58 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc