开发者

What's the difference between XSL Pattern and XPath in syntax?

I'm updating codes to use MSXML6.0 f开发者_StackOverflowrom MSXML3.0. However, I noticed that, for MSXML3.0, the default "SelectionLanguage" is "XSL Pattern", while MSXML6.0 only support XPath. I have concerns that this change would introduce differences in the query syntax.

Can somebody list the difference of syntax between these two syntax?


The one thing that has tripped me up is selecting the first node in a node set. For example, we'd been using MSXML 3.0 (which uses XSLPattern) and has queries like this:

/root/book[0]

This query was supposed to select the first book. This works with XSLPattern. But with XPath, this is correct:

/root/book[1]

So when I switched us to using MSXML 6.0, which uses correct XPath, all those queries with "[0]" stopped working.

Update: I just found this link that talks some more about XSLPattern and XPath:

MSDN Magazine: MSXML 3.0 Supports XPath 1.0, XSLT 1.0, XDR, and SAX2

http://msdn.microsoft.com/en-us/magazine/cc302348.aspx

Update #2:

Here's the W3C Spec on XSLT which includes XSL Patterns:

http://www.w3.org/TR/1998/WD-xsl-19981216.html#AEN376

Update #3

Here's another post that describes the same thing I mentioned above:

http://www.eggheadcafe.com/software/aspnet/29579789/xml-parsing.aspx


XSL Pattern, if I remember correctly, was a selection language like XPath but was implemented by Microsoft before XPath was standardised (possibly even created). I don't think anyone even has anything that documents XSL Pattern any more. You can basically forget about it and concentrate on XPath. It has the same purpose but is supported and standardised.


XSL Patterns appear to be part of WD-XSL, "working draft XSL", which means versions predating the XSL recommendation (1999), which differ significantly from the final 1.0 version.

Microsoft has the relevant info on "XSL Patterns". Here's a quote from the section XPath 1.0 APIs:

MSXML 2.0 provides support for XSL Patterns, the precursor to XPath 1.0. The notion of an XML addressing language was introduced into the original W3C XSL Working Drafts (http://www.w3.org/TR/1998/WD-xsl-19981216.html) and called XSL Patterns. MSXML 2.0 implements the XSL Patterns language as described in the original XSL specification with a few minor exceptions.

MSXML 3.0 provides support for the legacy XSL Patterns syntax as well as XPath 1.0.


XPath, in my experience, is much easier to get your head around. I avoid XSL like the plague if I can. But you are right, the syntax is very different, so if you want to switch from XSL to XPath you have some work ahead of you. I cannot explain the differences easily, but this tutorial should give you some idea of what XPath is about:

http://www.w3schools.com/XPath/xpath_examples.asp

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜