Skip to content

System.Xml.XPath to support XPath 2, XPath 3 and their XSLT variants #14819

Open

Description

@am11

Motivation

System.Xml.XPath currently conforms with XPath 1.0 [W3C-xpath-1] and XSLT 1.0 [W3C-xslt-1] standards, but not XPath 2.0 [W3C-xpath-2], XPath 3.0 [W3C-xpath-3], XPath 3.1 [W3C-xpath-3.1], XSLT 2.0 [W3C-xslt-2] and XSLT 3.0 [W3C-xslt-3].

The missing standard implementations in BCL are required by many consumer scenarios, for which .NET applications rely on third party libraries. One of the chief scenario is Content Query Web Part (CQWP) in SharePoint, where the users' XSLT code can be drastically minimized if v2 is supported by System.Xml.XPath. As for most parts, there are backward compatibility fallbacks available, that is; the code written in XSLT 2 precisely, can be expressed verbosely in XSLT 1 and since so forth.

Pitfalls

Unfortunately, (besides the existing third-party libraries' APIs) I do not have an off-hand -- concrete -- method list to propose, as it requires further brain-storming on whether to auto-select processor based on the input or to explicitly separate the namespaces (System.Xml.XPath2 and System.Xml.XPath3).

The point to ponder being; since the sub-languages XPath 2 and XPath 3 intrinsically facilitates backward compatibility modes, see XPath 2: J.1.3 Backwards Compatibility Behavior and XPath 3: 3.10 Backwards Compatible Processing, should the API be any different than the existing one and let consumers select the standard mode?

Activity

  1. joshfree commented on Oct 9, 2015

    @joshfree
    Member

    /cc @krwq @KrzysztofCwalina @piotrpMSFT

  2. PJungle commented on Feb 4, 2016

    @PJungle

    +1

    Please make this happen

  3. karelz commented on Oct 10, 2016

    @karelz
    Member

    We need API proposal. Anyone wants to do that?

  4. alirobe commented on Apr 5, 2017

    @alirobe

    Just wanted to add that this is one of the top 5 issues on UserVoice for .net at the moment. I know many devs who really need this. Lack of support for v2 has bit me many times in SharePoint and Umbraco. Similarly, I know of developers who have had to use unfamiliar stacks for application integrations (e.g. EDI/BizTalk type projects), simply due to lack of any support here. While I am not really capable of helping, I and many, many others am very keen to see this happen.

    https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/category/31481--net
    https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/4450357-implement-xslt-3-0-for-net
    https://visualstudio.uservoice.com/forums/121579-visual-studio-ide/suggestions/3795831-native-support-for-xpath-2-0-or-xslt-2-0-in-net

  5. karelz commented on Apr 5, 2017

    @karelz
    Member

    @alirobe thanks for the context, that is useful!
    To clarify: the ask on UserVoice is for XSLT 3.0. If we can implement it on top of .NET Standard 2.0, then also Desktop might benefit from it (out-of-band package). If it is not possible or if it is costly, then maybe it is incentive for people to move to .NET Core ;-)

    cc @sepidehms @krwq

    @danmosemsft maybe something to focus on after 2.0/2.1? You were collecting a list ...

  6. karelz commented on Apr 5, 2017

    @karelz
    Member
  7. alirobe commented on Apr 6, 2017

    @alirobe

    @karelz no problem! I don't really care where it gets implemented first, I just want a Microsoft API implementation somewhere... I'm sure that there will be enough demand to get that implementation surfaced everywhere. XPath & XSLT all need updating. XPath alone would be a great start, but they do kind of go together. :)

    Should it be raised as an issue here? Happy to do that if needed. I'm not familiar with the way MS works on this stuff, but as you've said, an a API proposal (followed by test suite) would be an obvious starting point, and actually fairly project-agnostic.

    Also, thanks so much for taking this seriously! This is something users have been crying for Microsoft to do for over 10 years. Anyone who does this will be a hero to tens of thousands of enterprise developers. I'm smiling just thinking of all the work-around code I will be able to delete! :)

  8. danmoseley commented on Apr 6, 2017

    @danmoseley
    Contributor

    @karelz it's already on my list. If I understand @krwq it seems it could be done while keeping our XML library netstandard 2.0 compilant. It is just resourcing and it's great to keep gathering evidence to bubble up the list when 2.0 is out the door.

  9. karelz commented on Apr 6, 2017

    @karelz
    Member

    @danmosemsft that's great news that we already have it on road map!

    @alirobe no need to file issues in .NET Standard -- .NET Standard is basically the common interface/intersection between Desktop (.NET Framework), .NET Core and Xamarin. If this can be implemented on top of .NET Standard, then all platforms will benefit. If it can't, it will be part of .NET Core future version, waiting for other platforms (Xamarin, Desktop) to catch up or be implemented as out-of-band package for those platforms, before we can add it to .NET Standard.

    Also, thanks so much for taking this seriously!

    BTW: We always take customer feedback and votes seriously. It sometimes might not look like that due to communication hiccups, or due to technical limitations (e.g. some changes in Desktop are breaking - a big no-no), but rest assured we do take it seriously (I believe it's true for all Microsoft, but I can at least guarantee it is true on .NET team).
    Of course, we can't in all cases commit to dates when things will be delivered (we have to align work with other priorities and other products, like Desktop - and we prefer to not communicate date when we are not 100% sure to avoid broken promises.
    In some cases we can't even commit if particular APIs will be delivered ever, especially when they are outside of our team/division ownership -- we have to work with partner teams inside Microsoft to come up with plans, and sometimes that takes time, and requires alignment of business priorities (the reality of large corporations). Nevertheless, in all cases, customers and success of .NET platform are in the center of our mind.

  10. krwq commented on Apr 6, 2017

    @krwq
    Member

    @danmosemsft @karelz - If we plan to reuse existing APIs I believe we will need some new switch/enum for tiny behavioral changes around parsing to not break any existing apps. Breaking changes would need to be opt-in. Anything else I believe is currently producing errors and would just start working after work is done. (I'd rather make people be more explicit about which version of XPath they choose)

    At minimum this will be few new properties (hopefully just one property and perhaps a new XPathExpression constructor). We would need to figure out major breaking changes between XPATH 1.0 <--> 3.0 and figure out advantages and disadvantages of each solution

  11. karelz commented on Apr 7, 2017

    @karelz
    Member

    @krwq this is interesting topic. We hit similar spec incompatibilities in Http space - dotnet/corefx#13036.

    If you think about this XPath case, can you imagine adding the spec-version choice as argument to constructor? Or is the relevant functionality exposed (also) as static methods?
    If it is via static methods (which is the case of dotnet/corefx#13036), then we either have to add spec-version argument to all of them, or create another class, or something. If that's the case, I'd like to start some general (in principle) API design discussions for these kinds of spec-versioned APIs -- please let me know where you think it falls. Thanks!

  12. krwq commented on Apr 7, 2017

    @krwq
    Member

    @karelz quick look it seems to me that we only have two overloads which take XPath expression: XPathExpression.Compile. I can see couple of options:

    • add a static property which would globally change the behavior (I'm not expecting anyone use two different versions of XPath in one project)
    • add new overloads - I do not like this approach as many overloads are simply confusing
    • a new class which would inherit from XPathExpression (i.e. XPath2Expression; XPath3Expression) which would set the flag per instance and never actually expose it directly

    I don't think it matters too much which option we choose - most likely people will always want the newest XPath and I'm not actually expecting breaking changes to hit too many people since even spec claims that the breaking changes were made because syntax was confusing.

    New class approach is probably the most discoverable since intellisense will suggest those options but likely will be a messier implementation with not much benefit.

    IMO static property because it is simplest and you do it once per app with not much downside.

  13. 109 remaining items

  14. michaelhkay commented on Apr 22, 2026

    @michaelhkay

    Indeed, XML has always remained popular with people who have to deal with complex documents, but the adoption of electronic invoicing is prompting a lot of people outside that community to rediscover it.

  15. TsengSR commented on Apr 22, 2026

    @TsengSR

    @dannyvv

    It's funny to see how many dev teams are embracing non Microsoft stack to solve this issue in Europe with the emergence of electronic invoicing. Who would have guess that this good old XML would resurface in 2026 ?

    Problem lies more in companies using ancient XML based formats in 2026, when you have gRPC, json and GraphQL, not the lack of XSLT processors for some ultra-niche use case.

  16. michaelhkay commented on Apr 22, 2026

    @michaelhkay

    using ancient XML based formats

    You're missing the point. XML has always been about stability and longevity, not about following the latest fashion. For financial documents you need to set a standard and stick with it for 50 years or more, you can't go making incremental improvements all the time. And electronic invoicing is hardly "ultra-niche".

  17. TsengSR commented on Apr 22, 2026

    @TsengSR

    You're missing the point. XML has always been about stability and longevity, not about following the latest fashion. For financial documents you need to set a standard and stick with it for 50 years or more, you can't go making incremental improvements all the time. And electronic invoicing is hardly "ultra-niche".

    Then people would still be using EDIfact. Obviously people are fed up with EDIfact and it being error prone due more and more people implementing it awfuly. You'd be surprised how many companies generate EDIfact files without any library just by concatting it or some spaghetti string splitting and you almost daily have issues with peoples documents not being processed due to some formatting or syntax errors, missing required fields and stuff.

    If people really would have wanted something stable with wide addopttion, then json would been the tool/format of choice. Its supported in litterally on any platform and guaranteed to last the next few decades.

    Unlike XSLT where you only have 1 ancient Java Library (Xalan), one not-so ancient Java library (Saxon) and one I forgot for C (iirc mostly ancient too, read: xstl 1.0 or so) and smoe half. Picking XML fora ny type of exchange format is the worst possible choice considering its platform adoptability. Its literally a lock-in in Java or C world.
    There's literally no usable XSLT processor other then the one you maintain. It's literally counter-intuitive to adopt/design an exchange format that only runs on a single platform, developed by a single company.

  18. michaelhkay commented on Apr 22, 2026

    @michaelhkay

    @TsengSR No doubt you could have designed it better if the job had been left to you. But it wasn't, it was done by international committees over many years (indeed decades). For those interested, there's a good summary of the state of play with e-invoicing standards at https://e-invoice.be/blog/xml-invoicing . If you're operating in this space, you don't get to choose what format to use, you have to live with what the experts have chosen. Standards are rarely perfect.

  19. alirobe commented on Apr 22, 2026

    @alirobe

    Oh man. I remember when I was a student, and I thought those sort of opinions mattered too. We should have some grace for people who have opinions unencumbered by reality. Just let it be. We all have more productive things we can do than engage with that.

    I like the idea of splitting this ticket into components. However given how well specified the problem domain is, I am curious if you could just feed this whole ticket into an LLM and have a first shot at a version. It would likely need some back/forth with the community to tease out design decisions; but honestly given the lack of interest from Microsoft, it might be better than nothing.

  20. tonyqus commented on Apr 22, 2026

    @tonyqus

    Sorry, I don't live in Europe. Can someone explain me what's the gap of EDIFact implemention in .NET? Which library do you usually use?

    I'm willing to dive into this and see whether I can fill the gap with a new open source library.

  21. AndersMad commented on Apr 22, 2026

    @AndersMad

    "To see life as it is, and not how it should be...." There is a reason HTML is not JSON, and Microsoft did not convert .csproj files to JSON either (they tried I believe). As a full-stack developer, I both love (and hate) XML and JSON - each has its pros and cons. Namespaces and comments in JSON? But the JSON vs. XML debate is pretty irrelevant to this thread, imho (spite I am at it here).

    And yes, why not give it a try with AI? By now I think it's pretty clear MS doesn't care much. I am going to try later to make it fully async XPath, a JSON navigator and extended language etc.

  22. alirobe commented on Apr 22, 2026

    @alirobe

    "To see life as it is, and not how it should be...."

    Indeed. The universe is not obliged to make sense to us.

    I'll be curious to hear how you go with it.

  23. am11 commented on Apr 22, 2026

    @am11
    MemberAuthor

    I like the idea of splitting this issue into smaller components.

    In my defense, this issue predates the documentation of the API review process (https://github.com/dotnet/runtime/blob/main/docs/project/api-review-process.md). I agree that, in its current form, it isn't specific enough to gain traction with maintainers or to be truly actionable. A concrete proposal would be needed. That said, there is also a valid counter‑argument: since most platforms don't provide these features out of the box, developers often rely on external libraries. In that sense, .NET isn't unique, though we still expect it to be the best/richest (in external library-free form). 😎

  24. TsengSR commented on Apr 22, 2026

    @TsengSR

    That said, there is also a valid counter‑argument: since most platforms don't provide these features out of the box, developers often rely on external libraries. In that sense, .NET isn't unique, though we still expect it to be the best/richest (in external library-free form). 😎

    I don't think people mind if its part of the runtime or external library, they more of "expect" it to be maintained by a big company (preferably the one who maintains the runtime) and with first-class support, i.e. utilizing all of the new performance benefits that .NET brought in since .NET Core 3.0 onwards) with the funds to do so rather than to depend on 1-man projects that would be abandoned at any point.

    System.Text.Json is a good example of this adoption and its received rather well, as its both from microsoft and a first-class citizen in .NET ecosystem.
    Most company I've worked with would plain out reject any library thats maintained as a hobby by a single person. And for most use-cases also reject a paid solution that costs middle 5 to 6-figure costs annually, as most customers these type of work/implementation is aimed towards are SMBs who simply won't pay 100k annually (or even single-time payment) to implement e-invoicing, order, delivery or whatever type of documents they need.

    The xslt technology has been very niche for the past 15-20 years, and being very niche usually means used/operated by enterprises, who are rather reserverd on takings risks on libraries or software with uncertain future. Most use-cases I've seen were migrating old systems based on it (BPM Workflow-Engines and SOAP Services namely, which is where a lot of the invoicing/order type of formates are processed in) or for formating documents (XML-FOP) for printing (including PDFs).

  25. michaelhkay commented on Apr 22, 2026

    @michaelhkay

    @TsengSR If you have good well researched data on adoption, it would be great to see it, because I don't, and it would add a lot of value to this thread. If you just want to share opinions based on your personal experience, then forget it: you don't see the big picture any more than anyone else does.

  26. wstaelens commented on Apr 22, 2026

    @wstaelens

    @michaelhkay go ahead and shake hands with Microsoft ;-)

  27. mikkeljohnsen commented on May 22, 2026

    @mikkeljohnsen

    Please implement this. We need this to validate OIOUBL Invoice etc. here i EU

  28. davidullrich commented on Nov 24, 2026

    @davidullrich

    For those following this long-running discussion, I’d like to share DCoding.Xml, an independent XML processing stack written in C# for .NET, supporting XSLT 2.0/3.0, XPath 2.0/3.0/3.1, and XQuery 1.0/3.0/3.1. You can find a more detailed list on the project page linked below.

    Planning and implementing started several years ago, following the discussions here and on Visual Studio UserVoice. The goal was to make modern XSLT and XPath readily accessible through APIs designed for .NET applications.

    The stack is modular, with independently usable XDM, XPath, XSLT, and XQuery components. In particular, XDM and XPath can be used without the transformation engine, which connects with the suggestion earlier in this thread to approach these as separate building blocks.

    The implementation includes LINQ to XML integration, asynchronous APIs with cancellation support, and NativeAOT support for the core XSLT, XPath, and XQuery APIs. A separate compatibility API helps migrate existing System.Xml.Xsl.XslCompiledTransform usage. Compatibility testing includes relevant tests drawn from dotnet/runtime.

    The Community edition is free of charge under a proprietary license and includes the core XSLT, XPath, and XQuery engines. A Professional edition provides additional capabilities like schema awareness and streaming.

    Project and downloads: https://www.d-coding.de/en/product/dcoding-xml
    Documentation and runnable examples: https://www.d-coding.de/en/docs/dcoding-xml
    Conformance and compatibility evidence: https://www.d-coding.de/en/docs/dcoding-xml/verification

    I’d also like to acknowledge @michaelhkay and the Saxonica team: working on an own implementation has given a much deeper appreciation of the high bar Saxon has set for standards support and performance.

    Further performance improvements and some feature updates are already being worked on. Feedback on existing stylesheets and real-world workloads would be very welcome, particularly the validation and transformation scenarios discussed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    api-suggestionarea-System.Xml

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions