Project

Profile

Help

XPath matches(text(), ... ) in Saxon 8.4

Added by Anonymous over 19 years ago

Legacy ID: #3249369 Legacy Poster: Marian Beniac (mbeniac)

Hello, I am using following expression to detect presence of nodes, which have text contents matching a regex: <xsl:if test="//*[matches(text(),'^p')]"> ... When running the XSLT containing the test, I get following message : XPTY0004: A sequence of more than one item is not allowed as the first argument of matches() I've tried the expression with the Altova tools and it works there... Am I doing something wrong ? Thanks, Marian


Replies (2)

RE: XPath matches(text(), ... ) in Saxon 8.4 - Added by Anonymous over 19 years ago

Legacy ID: #3249385 Legacy Poster: Michael Kay (mhkay)

This will fail if any element has more than one text node, that is, if an element has mixed content, or if it contains comments and processing instructions, or even if it contains inter-element whitespace between its child elements. It's best not to use text() when you want the string-value of an element. If you're looking for a text node that matches a regex, use //text()[matches(., '^p')]. If you're looking for an element whose string value matches the regex (i.e., ignoring comments and PIs), then use //*[matches(., '^p')]. Please don't use Altova's behavior as evidence of anything. Go to the spec.

RE: XPath matches(text(), ... ) in Saxon 8.4 - Added by Anonymous over 19 years ago

Legacy ID: #3249623 Legacy Poster: Marian Beniac (mbeniac)

Thanks a lot, it works now ... Marian

    (1-2/2)

    Please register to reply