使用xpath/xslt获取页面url的锚点部分
我正在使用 xpath 1.0 在 xslt 中编写一个模板,并且需要从当前页面的 url 访问锚标记。 例如,网址:
http://localhost/destinations/london.aspx#accommodation
我需要能够获取#accommodation并将其分配给一个变量。 我意识到使用 xpath 1.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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为什么这是一个 xpath 问题? URL 不是 XML 文档,因此 xpath 不适用。
XSLT 完全不知道页面位置等任何状态。 猜测一下您想要做什么,您可能最好从调用 XSLT 的层中的字符串操作或框架获取 #accomodation,并将值作为参数传递。
OTOH 也许这是无意义的,你的问题只需要澄清。
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 所说,这不是 XPath 问题。 它似乎也不是 XSLT 问题,尽管我可能是错的。 如果它与XSLT字符串解析有关,那么您需要的是类似这个问题 谈论。
您可能需要的是Javascript来获取当前URL(
document.location
),然后对其执行Javascript字符串解析。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.标准 XSLT 无法访问文档的 URL: http ://www.dpawson.co.uk/xsl/sect2/nono.html#d1974e804
一些供应商可能通过自定义属性提供此信息,但随后您将依赖于 XSLT 处理器。
如果您已设法以某种方式将 URL 放入 XSLT,那么我建议您必须采用简单的字符串操作来获取锚点。
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.