Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. XML / XSL
  4. passing a variable to xsl

passing a variable to xsl

Scheduled Pinned Locked Moved XML / XSL
xmlhelptutorialquestion
2 Posts 2 Posters 6 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Thesisus
    wrote on last edited by
    #1

    I thought this would be simple. I have a dictionary of sorts; I want to display just the terms in the XML doc. Then when I click on the term I'd like to see it's definition. The problem is how to pass the var to the xslt. ...make sense?

    E 1 Reply Last reply
    0
    • T Thesisus

      I thought this would be simple. I have a dictionary of sorts; I want to display just the terms in the XML doc. Then when I click on the term I'd like to see it's definition. The problem is how to pass the var to the xslt. ...make sense?

      E Offline
      E Offline
      Erik Westermann
      wrote on last edited by
      #2

      You can accomplish this, if you're doing this through a browser, with a little bit of processing either in the browser or on the server. In either case, the processing you do is the same. The short story is that you use an XPath expression to extract the value of the node(s) you want to display. Here are the details: I'm going to give you details from part of an example from my soon to be available book not for name recognition, but simply because it is a good example that demonstrates the technique. Assume that you have a site that publishes book reviews - the details of each book (title, author, etc) along with book reviews reside an an XML file that has a relative simple structure. When users hit the site, they receive a page that lists all books and provides a link to the review. The page, in one part of the sample, actually not an HTML page but is an XML file that's transformed on the client using XSL (so the URL users see in the address bar ends in a file name having an XML extension). This, so far, is the first bit of processing you need to do - transform the XML document (in your case the document that contains information about the directory) into a presentable format. The next bit of processing occurs when the user clicks on a record (or book review in this example) to get the details. I made this part of the process easier for myself back in the previous step: I generated links that provide the information I need in this step to extract the information the user wants. In the sample, I generate links that point to an HTML page along with some information on the querystring, to the link I generate looks something like this: <a href="displayReview.htm?Book Title">Book Title</a> So that when the user clicks the link, displayReview.htm can extract the review from the XML file. displayReview.htm contains a little bit of JavaScript that does the following:

      1. Extracts the text passed in on the querystring.
      2. Creates an instance of the XML DOM.
      3. Loads the book reviews document into the DOM.
      4. Creates another instance of the DOM.
      5. Loads an XSL file into the second DOM.
      6. Builds an XPath expression that includes the book's title.
      7. Uses the selectSingleNode method to execute the XPath query.
      8. Uses the transformNode method to transform the resulting node into some presentable format for the end user.
      9. Stuffs the result into the content of the HTML document.

      It looks rather involved here, but it is straight-forward once you see it in actio

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups