views:

1007

answers:

3

Hi

I'm writing a template in xslt with xpath 1.0 and need to access the anchor tag from the url of the current page. For example, the url:

http://localhost/destinations/london.aspx#accommodation

I need to be able to get #accommodation and assign it to a variable. I realise I'm somewhat limited by using xpath 1.0 - has anyone got any experience doing this?

Thanks, Adam

+2  A: 

Why is this an xpath problem at all? A URL is not an XML document, ergo xpath does not apply.

XSLT is completely unaware of any state like page location. Guessing a bit at what you're trying to do, you're probably best off getting #accomodation from string manipulation or framework in the layer which calls the XSLT, passing the value in as a param.

OTOH maybe this is nonsensical and your question just needs clarification.

annakata
A: 

As @Annakata said, this is not an XPath problem. It doesn't seem to be an XSLT problem either, though I may be mistaken. If it is related to XSLT string parsing, then what you need is something like this question talks about.

What you probably need instead is Javascript to get the current URL (document.location) and then perform Javascript string parsing on it.

Cerebrus
A: 

There is no way in standard XSLT to access to URL of a document : http://www.dpawson.co.uk/xsl/sect2/nono.html#d1974e804

Some vendors might provide this information via custom properties, but then you would be dependant on the XSLT processor.

If you have managed to get the URL into the XSLT in some fashion, then I suggest you will have to resort to simple string manipulation to get the anchor.

samjudson