[英]xquery regular expression…is there an easier way
嗨,我是xquery的新手,並且在xquery中使用了調節器表達式。 我有一個xml標記,我想找到它的某個位置。 somethingjpg,但找不到.jpg。 問題是somethingjpg並不總是在同一空間內。
這是一個xml示例:
<book title="Harry Potter">
<description
xlink:type="simple"
xlink:href="http://book.com/2012/12/28/20121228-there_is_somethingjpg_123456789a1s23e4.jpg"
xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
或xlink:href可以像這樣。
<book title="Harry Potter">
<description
xlink:type="simple"
xlink:href="http://book.com/2012/12/28/20121228-there_is_always_more_to_somethingelsejpg_123456789a1s23e4.jpg"
xlink:show="new">
As his fifth year at Hogwarts School of Witchcraft and
Wizardry approaches, 15-year-old Harry Potter is.......
</description>
</book>
我試圖實現的目標(如果可能的話)是一段xquery代碼,該代碼將查找somethingjpg或somethingelsejpg。 然后修復somethingjpg或somethingelsejpg只是說些什么或其他東西,再次將鏈接合並在一起,然后將新鏈接替換為eXist-db中的舊鏈接
我有代碼明智的..
let $a := collection('/db/articles/')//book
for $b in $a//@xlink:href[contains(.,'jpg_')]
let $c := tokenize(replace($b, 'Some sort of redex I can't figure out', '$1;$2;$3'), ';')
let $d := $c[2]
let $e := replace(substring-before($d, 'jpg_'). '_')
let $f := concat ($c[1]. $e, $c[3])
return update replace $b with $f
我只是想不通其余的...幫助!
您可能要使用eXist的XQuery Update工具
特別是, update replace expr with exprSingle
文檔update replace expr with exprSingle
顯示
如果[expr]是屬性或文本節點,則將屬性或文本節點的值設置為exprSingle中所有節點的串聯字符串值
因此,就像查找值一樣,找到其值包含'jpg_'字符串的屬性節點,然后簡單地將'jpg_'替換為空字符串(您甚至不需要正則表達式): replace($attr, 'jpg_', '')
for $attr in $a//@xlink:href[contains(.,'jpg_')]
let $newval = replace ($attr, 'jpg_', '')
return update replace $attr with $newval
另請參閱XQuery Update工具文檔 (當然,eXist可能會或可能不會完全實現,盡管它似乎足夠支持)
目前尚不清楚您確切要替換的內容以及為何要標記化的原因-您需要添加更多詳細信息,以防您不想簡單地從屬性值中刪除“ jpg_”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.