2

Update: I wrote up what I did, with source code and things to watch for, at - Adding XPath 2.0 functionality and variables to .NET XPath (my blog).

Is there a way to pass a regular expression to matches() for an XPath statement in .NET?

Example: do an xpath of

"/windward-studios/Employees/Employee[matches(string(LastName), '.*A?B[12]C.*')]"
David Thielen
  • 25,233
  • 30
  • 98
  • 177
  • Can you provide some examples of what you are trying to do? – cordsen Jun 22 '11 at 22:58
  • Interesting. Haven't had to use this xpath functionality so I didn't know it wasn't supported in .NET until seeing the answers. Looks like this other post http://stackoverflow.com/questions/1525299/xpath-and-xslt-2-0-for-net covers libraries that provide support in .NET . – bronsoja Jun 22 '11 at 23:26

2 Answers2

4

XPath 2.0 supports the matches function. However, .Net implements XPath 1.0.

You would need to add a custom function to implement match. See http://msdn.microsoft.com/en-us/library/ms950806.aspx

It looks like the Mvp.Xml Project: EXSLT.NET module implements most of XPath 2.0; including matches. See http://mvp-xml.sourceforge.net/exslt/

Richard Schneider
  • 34,169
  • 9
  • 55
  • 69
0

Microsoft's XSLT processor does not support XSLT 2.0, but there are at least two others available on .NET that do: Saxon and XQSharp.

Microsoft basically decided some time ago to go down a proprietary route with Linq, and if you want to stick with a standards-based approach, you will have to go to third parties.

Michael Kay
  • 147,186
  • 10
  • 83
  • 148