开发者

XPATH matches function problem-- works but doesn't work

I'm using Eclipse to run an XSL 2.0 (XPATH 2.0), and I have the following source:

<testTop>
    <Level1 id="abc" Text="from 1-2"/>
    <Level1 id="pqr" Text="from 3-44" />
    <Level1 id="xyz" Text="from 49-101" />
</testTop>

When I test the following expression in Eclipse, //*[matches(@Text, '\d+-\d+')] I get the right nodes, but not the Text attributes themselves

Level1 ID=abc
Level1 ID=pqr
Level1 ID=xyz

... whereas //@Text gives me the Text attributes. Can anyone help me to understand why?? I'd like to get the Text attribute values and parse them using string functions. THE END RESULT SHOULD LOOK LIKE THIS:

<output or开发者_JAVA百科iginalText="from 1-2" value1="1" value2="2" />

Shouldn't I be getting all the attributes that are part of each node that matched?


Your XPath is selecting the elements that have the attributes you want. If you want to select the @Text that match your pattern, you need to adjust your XPath to select the attributes rather than the element.

You could use this XPath:

//*[matches(@Text, '\d+-\d+')]/@Text

or this XPath:

//*/@Text[matches(., '\d+-\d+')]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜