使用xpath / xslt获取页面url的锚点部分

时间:2022-11-27 18:00:21

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:

我正在使用xpath 1.0在xslt中编写模板,需要从当前页面的url访问anchor标记。例如,网址:

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?

我需要能够获得#accommodation并将其分配给变量。我意识到使用xpath 1.0有点限制 - 有没有人有这方面的经验?

Thanks, Adam

3 个解决方案

#1


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

为什么这是一个xpath问题呢? URL不是XML文档,ergo xpath不适用。

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.

XSLT完全没有意识到页面位置等任何状态。稍微猜测一下你要做什么,你可能最好从调用XSLT的层中的字符串操作或框架中获取#accomodation,将值作为参数传递。

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

OTOH也许这是荒谬的,你的问题只需要澄清。

#2


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.

正如@Annakata所说,这不是XPath问题。它似乎也不是一个XSLT问题,尽管我可能弄错了。如果它与XSLT字符串解析有关,那么你需要的是这个问题所讨论的内容。

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

您可能需要的是Javascript获取当前URL(document.location),然后对其执行Javascript字符串解析。

#3


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

标准XSLT中无法访问文档的URL: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.

有些供应商可能会通过自定义属性提供此信息,但您将依赖于XSLT处理器。

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.

如果您已经设法以某种方式将URL放入XSLT,那么我建议您必须使用简单的字符串操作来获取锚点。

#1


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

为什么这是一个xpath问题呢? URL不是XML文档,ergo xpath不适用。

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.

XSLT完全没有意识到页面位置等任何状态。稍微猜测一下你要做什么,你可能最好从调用XSLT的层中的字符串操作或框架中获取#accomodation,将值作为参数传递。

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

OTOH也许这是荒谬的,你的问题只需要澄清。

#2


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.

正如@Annakata所说,这不是XPath问题。它似乎也不是一个XSLT问题,尽管我可能弄错了。如果它与XSLT字符串解析有关,那么你需要的是这个问题所讨论的内容。

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

您可能需要的是Javascript获取当前URL(document.location),然后对其执行Javascript字符串解析。

#3


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

标准XSLT中无法访问文档的URL: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.

有些供应商可能会通过自定义属性提供此信息,但您将依赖于XSLT处理器。

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.

如果您已经设法以某种方式将URL放入XSLT,那么我建议您必须使用简单的字符串操作来获取锚点。