XPATH - 将连接添加到多个属性中 [英] XPATH - add concatenation into multiple attributes
问题描述
这是我的代码:
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html xmlns:fb="http://www.facebook.com/2008/fbml" xmlns:og="http://opengraphprotocol.org/schema/">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<link rel="alternate" hreflang="en" href="http://www.example.com/page-59.html"/>
<div id="" class="pgLinks">
<a href="/example-text" class="guiArw sprite-pagePrev ">«</a>
<a href="/example-text-2" class="paging taLnk ">1</a>
<span class="paging pageDisplay">2</span>
当我运行此查询时,它返回页面上的顶部 URL "http://www.example.com/page-59.html" 或者如果此处出现1":
When I run this query, it returns either the top URL on the page "http://www.example.com/page-59.html" OR if it a "1" is present here:
<a href="/example-text-2" class="paging taLnk ">1</a>
它返回来自 href 的 URL,即:
it returns the URL from the href which is:
/example-text-2
问题是我想要完整的网址:
The thing is I want the full URL:
http://www.example.com/example-text-2
我基本上需要在第二部分添加一个 URL,以便它加入第二个结果(如果存在),所以它是这样的:
I basically need to add a URL to the second part of this so it joins the second result if present, so it is something like this:
(//link[@hreflang='en'] | "SITE URL HERE" //div[@class='pgLinks']/a[.='1'])[last()]/@href
我尝试过连接:
(//link[@hreflang='en'] | concat("http://www.example.com", //div[@class='pgLinks']/a[.='1']))[last()]/@href)
还有许多其他变体,包括使用管道|"但完全搞不懂.
And so many other variations including using the pipe "|" but cannot figure it out at all.
感谢您的帮助.
推荐答案
假设你只有xpath 1.0支持,你可以做xpath:
Assuming you only have xpath 1.0 support, you can do the xpath:
concat(
substring(
concat(
'http://www.example.com',
//div[@class='pgLinks']/a[.='1']/@href
),
1 div boolean(//div[@class='pgLinks']/a[.='1'])
),
substring(
//link[@hreflang='en']/@href,
1 div not(//div[@class='pgLinks']/a[.='1'])
)
)
这是一个关于实现 if-else 的 答案的应用声明.
This is an application of an answer on implementing an if-else statement.
这篇关于XPATH - 将连接添加到多个属性中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!