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 Programmer to Programmer discussions. This is a community of tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 22nd, 2009, 09:08 AM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Sep 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default General XSLT query

Hi

I am completely new to XML and XSL and now using an application call site publisher by Teamsite interwoven. I have managed to understand some basic XSL concepts but struggling with a problem I cannot seem to get my head round.

The left navigation from our site pulls in the links from a sitemap file which works great. The left nav has 3 levels of navigation and I am trying to create a simple xsl component to a content page which also reads in the site map links but what I am trying to do is:

Say I have 3 main links and 3 sublinks

Level one
Level one a
Level one b
Level one c
Level two
Level two a

etc. Whilst in level one, I have a link in the main content of the page at the footer with a link to level one a and so on. When I am on page level one c, I want the footer link to not to goto level two but to a seperate page.

So I would like to loop through the links and determine the page i'm on using a current page variable and do a comparison. When I get the match, I would like to check to see if there is a link after this, if so, show the next page link url, otherwise, goto a generic page (ie, hardcoded link).

Sorry if a bit vague but tried to explain in english.

Some code I have is:
<!-- get current page -->
<xsl:variable name "currpage">
<xsl:value-of select="/pagelocation/page_info/@pagename">
</xsl:variable>

Then to loop through the sitemap (3 altogher - one loop for each level of sitemap:-

<xsl:for-each select = "node[@visible-in-sitemap='true']">
Do some code in here. Currently just display value-of select="link/value"
</xsl:for-each>

Thank you to anyone who can help me. Maybe there is some easy syntax to do this but I do not know XSL much at all.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old June 22nd, 2009, 09:23 AM
mhkay's Avatar
Wrox Author
Points: 13,389, Level: 50
Points: 13,389, Level: 50 Points: 13,389, Level: 50 Points: 13,389, Level: 50
Activity: 82%
Activity: 82% Activity: 82% Activity: 82%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,025
Thanks: 0
Thanked 114 Times in 112 Posts
Default

Rather than describing your problem in terms of the user experience, it's much easier for us if you show the XML input and HTML output of your transformation, simplified as much as possible to remove irrelevancies.

Your code fragments mean nothing in the absence of a source document.

By the way

Code:
<xsl:variable name "currpage">
   <xsl:value-of select="/pagelocation/page_info/@pagename">
</xsl:variable>
is a verbose and inefficient (and sometimes incorrect) way of writing

Code:
<xsl:variable name "currpage" select="/pagelocation/page_info/@pagename"/>
Get out of the habit before it's too late.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old June 22nd, 2009, 10:58 AM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Sep 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi

Thank you for your quick reply. this is where I am stuck. The application I am using is Teamsite which I create the nav via a standard component within the web interface (hence not being able to see the xml it creates).

I can create my own components and got the sitemap xsl data from an xsl template in another component so can see the generated code to display the site map from the code I supplied.

I think my main question is knowing how to use xsl syntax to grab the current page url into a variable, then whilst in the loop, check to see if the loop variable is the same as the current page, if it is, then get the next url in the loop to use as a link. but then if it is the last page, no need to get the next url and and either leave blank or hard code a link.

I think it is just the xsl syntax I need to know. If anyone could give me a code example of how I could go about this, it will help millions. I could then try and translate into what I have got to work with.

Many thanks again.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old June 22nd, 2009, 11:01 AM
mhkay's Avatar
Wrox Author
Points: 13,389, Level: 50
Points: 13,389, Level: 50 Points: 13,389, Level: 50 Points: 13,389, Level: 50
Activity: 82%
Activity: 82% Activity: 82% Activity: 82%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,025
Thanks: 0
Thanked 114 Times in 112 Posts
Default

Sorry, but without knowing what the XML input looks like, writing XSLT to process it is impossible.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #5 (permalink)  
Old June 22nd, 2009, 11:12 AM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Sep 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Would it be possible to make a dummy input xml just so I can understand?

for example:
<code>

<sitemap>
<navlink>
<linkname>some link one</linkname>
<linkpath>http//www.linkone.com</linkpath>
</navlink>
<navlink>
<linkname>some link two</linkname>
<linkpath>http//www.linktwo.com</linkpath>
</navlink>
<navlink>
<linkname>some link three</linkname>
<linkpath>http//www.linkthree.com</linkpath>
</navlink>
</sitemap>

</code>

Then I would use the <xsl: template match="sitemap"> and use the for-each select to do the code?

Or have I totally lost it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #6 (permalink)  
Old June 22nd, 2009, 11:22 AM
Friend of Wrox
Points: 3,389, Level: 24
Points: 3,389, Level: 24 Points: 3,389, Level: 24 Points: 3,389, Level: 24
Activity: 66%
Activity: 66% Activity: 66% Activity: 66%
 
Join Date: Nov 2007
Location: Germany
Posts: 701
Thanks: 0
Thanked 109 Times in 108 Posts
Default

XSLT does not have loops. I am also not sure what you expect the "current page url" to be. You can however pass parameters to an XSLT stylesheet thus you can define a global parameter
Code:
<xsl:param name="cp"/>
in your stylesheet, set it with the API your XSLT processor exposes to your environment, pass in what you regard as the current page url and then use that parameter in XPath expressions e.g.
Code:
<xsl:template match="sitemap">
  <xsl:value-of select="navlink[linkpath = $cp]/following-sibling::navlink[1]/linkpath"/>
</xsl:template>
will output the linkpath of the first navlink sibling of that navlink element where linkpath is equal to the parameter.
__________________
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
  #7 (permalink)  
Old June 22nd, 2009, 12:10 PM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Sep 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Aah. I assume I am using Xpath then. Here is the code cut n paste which I have so far. My code just displays all the left nav links from the sitemap at the moment but you can see how it is generated using a loop.

I guess if you cannot help me from this code then i'm stuck and will have to go back to the teamsite supplier for help. I assumed it would be a general XSL question but guess it is a bit more difficult than I first thought. I hate being a newby to stuff like this.

Here is the code pasted straight from the app...

this gets the sitemap info
Code:
<Data>
  <External>
    <Object Scope="local">com.interwoven.livesite.external.impl.LivesiteSiteMap</Object>
    <Method>getSiteMap</Method>
  </External>
</Data>
and this does the loop and displays the links
Code:
<!DOCTYPE html-entities SYSTEM "http://www.interwoven.com/livesite/xsl/xsl-html.dtd">
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <!-- Skin: Default (Default Browser Type) -->

  <xsl:include href="http://www.interwoven.com/livesite/xsl/HTMLTemplates.xsl"/>
  <xsl:include href="http://www.interwoven.com/livesite/xsl/StringTemplates.xsl"/>

  <!-- FOR TESTING -->
  <xsl:variable name="currPage">investments/individual_saving_accounts/how_to_apply</xsl:variable>

<!-- USE THIS WHEN READY TO GO LIVE
    <xsl:variable name="currPage">
        <xsl:value-of select="/Properties/Data/Result/page_info/@pagename" />
    </xsl:variable>
-->


  <xsl:template match="/">
    <xsl:apply-templates select="/Properties/Data/Result/site-map/segment"/>
  </xsl:template>

  <xsl:template match="segment">
       <div class="">



        <xsl:for-each select="node[@visible-in-sitemap='true']">
          <ul class="sitemapLevel1">
          <li>LEVEL1: - <xsl:value-of select="link/value"/></li>

          <xsl:for-each select="node[@visible-in-sitemap='true']">
             <ul class="sitemapLevel2">
             <li>&nbsp;&nbsp;&nbsp;&nbsp;LEVEL2: - <xsl:value-of select="link/value"/> </li>

             <xsl:for-each select="node[@visible-in-sitemap='true']">
                <ul class="sitemapLevel3">
                <li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-LEVEL3: - <xsl:value-of select="link/value"/> </li>
                </ul>
             </xsl:for-each>

             </ul>
          </xsl:for-each>
          </ul><br/>
       </xsl:for-each>



       </div>
      
<!--        <p class="next"><a href="#"><xsl:value-of select="$currPage"/></a></p> -->

        <p class="next"><a href="#"><xsl:value-of select="$currPage"/></a></p>

  </xsl:template>


<xsl:template name="navLink">
   <!-- output  node as a link -->
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="link/value"/>         
      </xsl:attribute>
      <xsl:attribute name="title">
         <xsl:value-of select="description"/>
      </xsl:attribute>
      <xsl:value-of select="label"/>
   </a>                
</xsl:template>



</xsl:stylesheet>
It is difficult to show you the outputted style text but the output in text form is:

LEVEL1: - index

LEVEL1: -
LEVEL2: - linkhere
LEVEL2: - linkhere
-LEVEL3: - linkhere
LEVEL2: - linkhere
LEVEL2: - linkhere

LEVEL1: - linkhere

LEVEL1: - linkhere

LEVEL1: - linkhere
LEVEL2: - linkhere
-LEVEL3: - linkhere
-LEVEL3: - linkhere
-LEVEL3: - linkhere
-LEVEL3: - linkhere
-LEVEL3: - linkhere
LEVEL2: - linkhere
-LEVEL3: - linkhere
-LEVEL3: - linkhere

LEVEL1: - linkhere

LEVEL1: - linkhere

LEVEL1: - linkhere
LEVEL2: - linkhere

actual href link here (just for testing of the style but will be in the loop)
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #8 (permalink)  
Old June 22nd, 2009, 12:31 PM
mhkay's Avatar
Wrox Author
Points: 13,389, Level: 50
Points: 13,389, Level: 50 Points: 13,389, Level: 50 Points: 13,389, Level: 50
Activity: 82%
Activity: 82% Activity: 82% Activity: 82%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,025
Thanks: 0
Thanked 114 Times in 112 Posts
Default

I don't think that writing the XSLT code will be at all difficult if you can only find a way to tell us clearly what its inputs and outputs are.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #9 (permalink)  
Old June 22nd, 2009, 01:30 PM
Authorized User
Points: 56, Level: 1
Points: 56, Level: 1 Points: 56, Level: 1 Points: 56, Level: 1
Activity: 2%
Activity: 2% Activity: 2% Activity: 2%
 
Join Date: Sep 2008
Location: , , .
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Maybe if I could get some help with some imaginery input and outputs? then I could try and work out how to get the real ones later? At this stage, it would be good to know how the syntax would work? Once I can do that, I could translate later?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #10 (permalink)  
Old June 22nd, 2009, 01:46 PM
Friend of Wrox
Points: 3,389, Level: 24
Points: 3,389, Level: 24 Points: 3,389, Level: 24 Points: 3,389, Level: 24
Activity: 66%
Activity: 66% Activity: 66% Activity: 66%
 
Join Date: Nov 2007
Location: Germany
Posts: 701
Thanks: 0
Thanked 109 Times in 108 Posts
Default

Then provide the imaginery input and the corresponding output you want the stylesheet to create. You did already provide some input however and I posted an XPath expression to find a certain node in that input.
__________________
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
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 12:10 PM.


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