2012-06-06 59 views
0

我有這樣的XML:XSL - 匹配節點的文本和追加另一節點兄弟

<a> 
    <b> 
    <c>some text here</c> 
    </b> 
</a> 
<a> 
    <b> 
    <c>another cool text</c> 
    </b> 
</a> 

我需要匹配一個字「爽」裏面// A/B/C /文本()和變換這樣

<a> 
    <b> 
    <c>some text here</c> 
    </b> 
</a> 
<x> 
    <y> prepend to cool text </y> 
</x> 
<a> 
    <b> 
    <c>another cool text</c> 
    </b> 
</a> 

的XML我嘗試這樣做:

<xsl:template 
     match="//a/b/c/matches(text(),'\.*cool\*.')"> 
... 
</xsl:template> 

,但沒有運氣:

XTSE0340: XSLT Pattern syntax error at char 153 on line 30 in {...\.*cool\*...}: 
    Function call may appear only at the start of a pattern 

我在這裏錯過了什麼?

回答

1

你的比賽是不正確的,應該括號內[]測試:

<xsl:template 
     match="//a/b/c[matches(text(), '.*cool.*')]"> 
... 
</xsl:template> 

此外,如果你的正則表達式是那麼容易,那麼你可以使用XPath方法。

+0

謝謝,那是我正在尋找的,在我的情況下,它並不是那麼簡單,所以我真的需要正則表達式。無論如何,謝謝你的快速回答! – jdevelop

+0

不客氣! – Alex

相關問題