0

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

3 Answers 3

2

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.

0

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.