[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

set xslt variable from browser url (using javascript)


Subject: set xslt variable from browser url (using javascript)
From: Jaime Tanna <jaime_tanna@xxxxxxxxxxx>
Date: Tue, 15 Jun 2004 12:06:27 +0100 (BST)

Hi,

I am trying to set a variable (name="targetPosition")
in my xslt stylesheet from the browser url.

The url in the browser could be in this format:

http://www.ivillage.co.uk/travel/whatsonwhen/city/0,,amsterdam-2,00.html
(storyserver generated url).

I am trying to pull out the number after the hyphen,
so in this case I would want to set my global variable
(targetPosition) to 2.

This will then enable my stylesheet to pull the
required (in this case second) <section> node of the
amsterdam.xml document.

Many thanks if anyone can shed some light here.  My
friend and I are really stuck!

Jaime

------------------------------------------

Here is the xml document ("amsterdam.xml") which calls
my stylesheet ("wow.xsl"):

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="wow.xsl"?>
<!DOCTYPE wowDestination SYSTEM
"./whatsonwhen.destination.dtd">
<wowDestination id="12345" location="Amsterdam"
lang="en-gb">
    <section title="Overview">
        <image
src="http://xml.whatsonwhen.com/img_bg/9736.jpg"
caption="Amsterdam canals. Photo credit to Miranda
Wilson"/>
        <p>A jewel in Europe's crown, Amsterdam is the
political, economic and cultural capital of the
Netherlands
            (Holland), located on an inlet of the
North Sea. The city became prominent thanks to trade
with Asia during
            the 17th century. The canal-side, gabled
warehouses where tall ships unloaded cocoa, coffee and
spices form
            the historic centre today. </p>
        <p>A city of graceful bridges, quiet trams and
platoons of bicycles, Amsterdam has a reputation for
tolerance
            and innovation. A multicultural city, it
is home to the Royal Concertgebouw Orchestra, the
world-class art
            collections of the Rijksmuseum, Stedejlik
and Van Gogh museums and a lively nightlife. </p>
    </section>
    <section title="Essentials">
        <p>
            <ul>
                <li>
                    <b>Electricity</b> - 220V AC,
50Hz</li>
                <li>
                    <b>Visas</b> - Aus/EU/US none
</li>
                <li>
                    <b>Dialling code</b> - +31
(national), (0) 20 (city) </li>
                <li>
                    <b>Health</b> - no vaccinations
needed, tap water safe</li>
                <li>
                    <b>Money</b> - euro (?)</li>
                <li>
                    <b>GMT</b> - +1</li>
                <li>
                    <b>Tourist Information</b> -
Amsterdam Tourist Board, 10 Stationsplein, 1012 AB
Amsterdam, +31 (0)
                    20 20 18800.</li>
                <li>
                    <b>City Population</b> - 0.7
million</li>
            </ul>
        </p>
    </section>
    <section title="Getting There and Away">
        <p>
            <b>By Air</b>: Schiphol International
Airport (AMS) airport is 18km southwest of the city
centre. The
            national airline is KLM - Royal Dutch
Airlines. </p>
        <p>
            <b>Getting to and from the Airport </b>:
Trains run to Amsterdam Centraal Station every 15
minutes (journey
            time 20 mins). Taxis take 20 minutes and
buses 30 minutes. </p>
        <p>
            <b>By Rail</b>: Centraal Station is
situated at the Stationsplein 2km north of the
Leidscheplein.
            Nederlandse Spoorwegen, the national rail
operator, runs efficient and frequent services to
Holland and the
            rest of Europe. </p>
        <p>
            <b>By Road</b>: The A10 encircles
Amsterdam. For Brussels and Utrecht take the A2
heading south. Schiphol
            Airport is on the E19. </p>
    </section>
    <section title="Getting Around">
        <p>
            <b>Orientation</b>: Dam Square is the
heart of the city, from which four canals radiate in
concentric
            circles. The larger parks and museums of
the city are found to the south, while Centraal
Station is north of
            the city centre, near to the Red Light
district. Beyond Centraal Station, the derelict,
19th-century
            docklands of Oosterlijk Havengebied have
recently been transformed into a smorgasbord of modern
            architectural treats: 8,000 homes,
cultural centres, hotels and interior design shops. To
cross from one
            side of central Amsterdam to the other
takes 30 minutes on foot. </p>
        <p>
            <b>By Bus</b>: Several bus lines connect
the centre with Amsterdam's suburbs. Night buses run
well after midnight.</p>
        <p>
            <b>By Bicycle</b>: A pleasant way to get
around the city, particularly if longer trips are
planned. There
            are 500,000 bicycles in the city! </p>
        <p>
            <b>On Foot</b>: The city is best
appreciated on foot and distances are rarely more than
a half-hour walk. </p>
        <p>
            <b>By Metro</b>: There are three metro
lines serving the southeast of the city and the
suburbs. Trains
            depart from Centraal Station and run daily
6.30am-12.15am. </p>
        <p>
            <b>By Tram</b>: A scenic method of
transportation, trams run from 6am-12am daily and are
the fastest way to
            get around Amsterdam. Tram 20 runs past
most key tourist attractions. Route maps are available
in tourist
            offices and Centraal Station. </p>
        <p>
            <b>By Taxi</b>: Taxis showing a yellow
light can be hailed. Alternatively, taxis can be
booked through the
            Central Taxi Office (+31 (0) 20 677 7777).
</p>
    </section>
    <section title="Dining">
        <p>Key dining districts include Jordaan, a
blue-collar, residential district which is being
steadily colonised
            by bohemian types, with its many
restaurants and <i>eetcafés</i> (gastropubs). The
'Nine Alleys' of the Old
            Side and The Dam are peppered with smart
eateries, many of them found in 17th century canal
side townhouses.
            Indonesian restaurants around the
Leidseplein specialise in Dutch banquets known as
<i>rijsttafel</i> ('rice
            table') while traditional Dutch fare,
<i>erwtensoep</i> (thick pea soup) and <i>stamppot</i>
(mashed
            potatoes with sausage), are easily sought
out in De Pijp. </p>
        <p>Restaurants are open from 11am until
midnight. Tipping is not compulsory, though 5-10% tips
are appreciated.
            For the up-market restaurants below, book
in advance and wear smart casual dress. Expect to pay
around
            ?80-?120 per person for a three-course
meal with wine in the restaurants suggested below.</p>
        <section type="Gourmet" title="Restaurant
Christophe">
            <p>Michelin-starred owner/chef
Jean-Christophe Royer injects Algerian flavours of
home into classic French dishes.</p>
            <p>46 Leliegracht (Behind Westerkerk), +31
(0) 20 625 0807. Tue-Sat dinner only.</p>
            <email>info@xxxxxxxxxxxxx</email>
        </section>
        <section type="Luxury" title="La Rive">
            <p> Michelin-starred haute cuisine and a
formidable, temperature-controlled wine cellar of
3,000 bottles.</p>
            <p> Amstel Inter-Continental Hotel, 1
Professor Tulpplein (Wibaudsteraat metro), +31 (0) 20
520 3264.
                Mon-Fri, lunch and dinner, Sat dinner
only.</p>
            <email>larive@xxxxxxxxxxxxx</email>
        </section>
        <section type="Business" title="Blakes">
            <p>Hempel designed interior, with a fusion
menu inspired by Dutch adventurers in the Golden Age.
</p>
            <p>Blakes Hotel, 384 Keizergracht (Spui),
+31 (0) 20 530 2010. Mon-Fri lunch and dinner, Sat
dinner only,
                Sun brunch only. </p>
            <email>hotel@xxxxxxxxx</email>
        </section>
        <section type="Night Out" title="Supperclub">
            <p> A restaurant, art gallery, fashion
show, stage set, bar and club rolled into one,
designed to blast all
                the senses.</p>
            <p>21 Jonge Roelensteeg (Dam Square), +31
(0) 20 344 6400. Open daily, dinner only.</p>
            <email>reservation@xxxxxxxxxxxxx </email>
        </section>
        <section type="In Vogue" title="Blender">
            <p>Chrome, curves, cocktails and fine food
at this DJ bar/restaurant. Try the terrace for
al-fresco dining
                in summer.</p>
            <p>16 Van der Palmkade (train 10 to
Widdenkad), +31 (0) 20 486 9860. Dinner only Tue-Sun.
</p>
        </section>
    </section>
    <section title="Nightlife">
        <p>Dutch gin ( <i>genever</i>) and Heineken
are the tipples of choice for Dammers, who head to the
            Rembrantsplein-Leidseplein for live music
and dancing (clubs Melkweg and Paradiso are good
options). The Red
            Light district is notoriously 'open' and
is found east of Centraal Station. Special cafés offer
marijuana
            menus while cool bars are scattered all
over the centre of Amsterdam. Clubs open at 10pm and
close at 4am
            Monday to Friday and 5am at weekends.
Thursday and Saturday nights are busiest. </p>
    </section>
    <section title="Sightseeing">
        <p>Amsterdam is a culture vulture's dream -
easy to explore on foot, crammed with treasures and
boasting the
            largest historic centre in Europe. What's
more, the museums are conveniently bunched together
south of the
            Leidseplein. To appreciate the
17th-century merchant houses lining the Dam's curvy
canals, a canal tour is
            recommended. </p>
        <p>But Amsterdam is more than the sum of its
Golden Age, as a trip to the transformed, 19th-century
docklands of
            Oosterlijk Havengbied can reveal. Here,
the various 'islands' of docks have been redeveloped
by
            world-acclaimed architects. The bridges of
Java Island are particularly spectacular. </p>
        <p>Top tip: The Amsterdam Pass, for sale at
city tourist offices, offers free entry to museums,
canal cruises
            and more.</p>
        <section type="art" title="Van Gogh Museum">
            <p> A stunning collection of the renowned
Dutch artist's work featuring 200 paintings and 500
drawings. The
                new wing by Kisho Kurokawa is known as
'the Oyster'. </p>
            <p>7 Paulus Potterstraat (Museumplein),
+31 (0) 20 5705200. Open daily.</p>
        </section>
        <section type="attraction" title="NEMO">
            <p>This museum is dedicated to scientific
discoveries. Designed by award-winning Renzo Piano, it
resembles
                the hull of an enormous ship. </p>
            <p>2 Oosterdok (Centraal Station), +31 (0)
20 531 31 38. Closed Mon.</p>
        </section>
        <section type="art" title="Rijksmuseum">
            <p>A treasure trove of painting from
Holland's Golden Age - Rembrandt, Vermeer, Hals, plus
precious Asian
                art and Delft blue collections. For
modern art, head next door to the Stedelijk
Museum.</p>
            <p>42 Stadhouderskade (Museumplein), +31
(0)20 6747047. Open daily.</p>
        </section>
        <section type="attraction" title="Anne Frank's
House">
            <p>A poignant reminder of the Holocaust,
Anne Frank penned her famous diary during the Second
World War
                while hiding in this now famous
house.</p>
            <p>267 Prinsengracht Centraal Station),
+31 (0)20 5567100. Open daily. </p>
        </section>
        <section type="park" title="Keukenhof
Gardens">
            <p>An hour from Amsterdam, these gardens
bloom from spring to autumn with millions of bulbs.
</p>
            <p>Keukenhof, just outside Lisse (train to
Leiden, then bus 54), +31 (0) 25 246 5555. Open 21
March-18 May. </p>
        </section>
    </section>
    <section title="Shopping">
        <p>There's more to take home from Amsterdam
than clogs and <i>dropjes</i> (Dutch sweets). Cornelis
Schuytstraat
            is lined with designer label boutiques as
is P.C Hooftstraat, just south of Leids. This is the
            shoppingstreet located practicly direct
south of the Leidscheplein. De Bijenkorf and Magna
Plaza are the
            city's two major department stores. For
the latest in modern design trends, visit the
converted 1900 cocoa
            warehouse Pakhuis Amsterdam in Oosterlijk
Havengebied. </p>
        <p>The canals of Keizergracht, Prinsengracht
and Herengracht are home to numerous modern art
galleries, while
            the Spui holds a contemporary art market
each Sunday. Pricey antiques of high quality are found
at
            Spiegelkwartier. The prettiest market of
them all however has to be the flower and bulb market
on the Singel
            canal (Koningsplein).</p>
    </section>
    <section title="Business">
        <p>
            <b>Do</b> be formal to begin with, until
you get to know your Dutch colleagues. Expect to be
called by your
            surname and wear suits to a meeting. </p>
        <p>
            <b>Don't</b> be late - the Dutch are very
punctual. Don't forget to bring flowers or a small
gift if invited
            to an associate's home.</p>
        <p>
            <b>Business Hours</b>: 8.30am-5pm Monday
to Friday with half an hour for lunch. </p>
        <p>
            <b>Key Industries</b>: Banking, insurance,
fashion, flowers, media, telecommunications and
tourism.</p>
        <p>
            <b>Key Districts</b>: The RAI
International Congress Center (Europaplein) and the
city centre, Amstelveen
            (advertising, computing, KLM), Aalsmeer
(horticulture) and Zaanstad (food processing).
South-Axes (Zuidas,
            in Dutch) is increasingly a key banking
district near the World Trade Centre, south of the A10
ringroad
            where ABN-Amro and ING Banks have their
headquarters. This area is connected to the city by
the Metro.</p>
    </section>
    <section title="Language Tips">
        <p> Dutch is the national language but almost
everyone, without exception, speaks perfect English.
They will
            certainly be surprised - and pleased - if
you manage to utter a word in Dutch.</p>
        <p>
            <ul>
                <li>My name is - Ik heet</li>
                <li>Please - Alstublieft</li>
                <li>Thank you - Dank u wel</li>
                <li>Hello - Hallo</li>
                <li>How are you? - Hoe gaat het? </li>
                <li>Goodbye - Tot ziens</li>
                <li>How much? - Hoeveel kost dat?</li>
                <li>I don't understand! - Ik begrijp
het niet!</li>
                <li>Cheers! - Proost! </li>
            </ul>
        </p>
    </section>
    <section title="Links">
        <p>
            <ul>
                <li>
                    <a
href="http://www.visitamsterdam.nl"
target="_blank">Amsterdam Tourist Board</a>
                </li>
                <li>
                    <a href="http://www.schiphol.nl"
target="_blank">Schiphol International Airport</a>
                </li>
                <li>
                    <a href="http://www.ns.nl"
target="_blank">Dutch Railway Network</a>
                </li>
                <li>
                    <a href="http://www.apti.is.nl"
target="_blank">Amsterdam Public Transport System</a>
                </li>
                <li>
                    <a
href="http://www.globalrefund.com"
target="_blank">Shopping Tax Guide</a>
                </li>
            </ul>
        </p>
    </section>
</wowDestination>

------------------------------------------

Here is the xslt stylesheet ("wow.xsl"):

<?xml version="1.0"?> 
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:lxslt="http://xml.apache.org/xslt"
        xmlns:result="here"
        extension-element-prefixes="result"
        version="1.0">

<lxslt:component prefix="result"
elements="setPosition" functions="">
  <lxslt:script lang="javascript">
    function setPosition(xslContext, elem) {    
      var urL = 'document.location';
      var urLBits = urL.split("-");
      var section = /^[0-9]{1,2}/   
      myNode = xslContext.getContextNode();
      myNode.getAttribute("targetPos") = section;
    }    
  </lxslt:script>
</lxslt:component>

<result:setPosition targetPos=""/>

<xsl:variable name="targetPosition"/>

<xsl:template match="/">
  <html>
    <head>     
      <link rel="stylesheet" type="text/css"
href="http://www.ivillage.co.uk/new_css/0,,563191,00.css"/>
    </head>
    <body>
      <table width="440" cellspacing="0"
cellpadding="0" border="0">
        <tr>		
          <td class="wow">
            <xsl:apply-templates
select="wowDestination"/>
          </td>
        </tr>
      </table>
    </body>
  </html>  
</xsl:template>

<xsl:template match="wowDestination">  
  <h1>
    <xsl:value-of select="@location"/>
  </h1>
  <xsl:apply-templates select="section"/>
    <div class="disclaimer">
      <b>Disclaimer</b>: Although we've tried to make
the information on this web site 
      as accurate as possible, we accept no
responsibility for any loss, injury or 
      inconvenience sustained by any person resulting
from information published on 
      this site. We encourage you to verify any
critical information with the relevant 
      authorities before you travel. This includes
information on visa requirements, 
      health and safety, customs, and transportation.
<br /><br />  
      Copyright &#38; 2003 <a class="disclaimer"
href="http://www.whatsonwhen.com/"
target="_blank">Whatsonwhen Ltd</a>
    </div>
</xsl:template>

<xsl:template match="section">
  <xsl:if
test="parent::node()[name()='wowDestination'] and
position()=$targetPosition">
    <h2>
      <xsl:value-of select="@title"/>
    </h2><br /><br />
    <xsl:apply-templates select="image"/>
    <xsl:apply-templates select="p"/>
    <xsl:apply-templates select="email"/>
    <xsl:apply-templates select="section"/>
  </xsl:if>
  <xsl:if test="parent::node()[name()='section']">
    <h4>
      <xsl:value-of select="@title"/>
    </h4>
    <xsl:apply-templates select="image"/>
    <xsl:apply-templates select="p"/>
    <xsl:apply-templates select="email"/>
    <xsl:apply-templates select="section"/>
  </xsl:if>
</xsl:template>

<xsl:template match="image">
  <img src="{@src}" alt="{@caption}" align="right"/>
</xsl:template>

<xsl:template match="p">
  <p><xsl:apply-templates/>
    <xsl:for-each select="child::node()">
      <xsl:apply-templates/>
    </xsl:for-each>
  </p>
</xsl:template>
      
<xsl:template match="b">  
  <b>
    <xsl:value-of select="."/>
  </b>
</xsl:template>     
      
<xsl:template match="i">  
  <i>
    <xsl:value-of select="."/>
  </i>
</xsl:template>       
      
<xsl:template match="a">  
  <a href='{@href}' target='{@target}'/>
</xsl:template>
     
<xsl:template match="ul">  
   <ul>
     <xsl:apply-templates select="li"/>        
   </ul>  
</xsl:template>

<xsl:template match="li">  
  <li>
    <xsl:value-of select="."/>
  </li>
</xsl:template>

<xsl:template match="email">  
  <a href="email:{.}">
    <xsl:value-of select="."/>
  </a><br/>
</xsl:template>

</xsl:stylesheet>


	
	
		
___________________________________________________________ALL-NEW Yahoo! Messenger - sooooo many all-new ways to express yourself http://uk.messenger.yahoo.com


Current Thread
Keywords