XSLT 2.0 intellisense in Visual Studio 2010 - Addi

2020-02-09 18:45发布

问题:

I want to be able to get intellisense in XSLT but for version 2.0 in visual studio

I know by default XSLT 2.0 isn't support - only 1.0 - but using Saxon API you can use XSLT 2.0.

I would love to get intellisense, i think this is possible by adding a XSLT 2.0 schema to visual studio but i am not 100% sure.

My question really is where do i get the schema from , i presume i can download it ?

and where do i install it in visual studio?

回答1:

I'm not certain but, I think this is the schema you want from the W3 site: http://www.w3.org/2007/schema-for-xslt20.xsd

The existing xslt.xsd file (on my install) is here: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Xml\Schemas\

Please could you post back your results - this looks quite interesting.



回答2:

I had to tweak to get VS2010 Professional to show Intellisense for XSLT 2.0. First, download the file http://www.w3.org/2007/schema-for-xslt20.xsd. You'll then need to edit the file and remove 'schemaLocation' attributes from both 'xsl:import' elements which are located at the beginning of the document after the comments. Then copy this modified file to [Your Visual Studio 10.0 Installation Folder]\Xml\Schemas. If you have VS running restart it. Open your XSLT file so that the XML menu is visible and goto 'XML->Schemas...'. There you will find both version 1.0 and 2.0 schemas for XSLT. You'll need to disable version 1.0 by clicking under its 'Use' field and selecting 'Don't use this scheme'. Now the Intellisense should work.

The requirement to remove 'schemaLocation' attribute may have something to do with .NET security blocking XML documents from retrieving documents from web. I'm not sure. Anyways, the files are available locally so this shouldn't be any problem.

The editor should have selected the version 2.0 of the schema by looking at <xsl:stylesheet version="2.0"...> but I'm not a XML guru so there may be a better workaround than disabling schema version 1.0.