29 Jan 2009

XSD schema validation for XSL and auto-completion in eclipse (second edition)

In Jan 8, 2006 I made a post about making xsl autocompletion work under eclipse... but I was in a hurry so the old post is not top quality ;)

Let fix it and make it a first class citizen :)

First you can download 2 already pre-configured empty files:

  • test-default-namespace.xsl

    <?xml version="1.0" encoding="UTF-8"?>
    <stylesheet xmlns="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemalocation="http://www.w3.org/1999/XSL/Transform
    http://www.w3.org/2005/02/schema-for-xslt20.xsd"
    version="2.0">

    </stylesheet>


  • test-not-default-namespace.xsl

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemalocation="http://www.w3.org/1999/XSL/Transform
    http://www.w3.org/2005/02/schema-for-xslt20.xsd"
    version="2.0">

    </xsl:stylesheet>


Now you need to setup eclipse, Go to Windows > Preferences then XML > XML Catalogs.
Copy the exact same informations that the screen capture below!!




Validate your the xsl with Right click on the file in eclispe > Validate

When you hit Ctrl+Space, it should work now!
You shouldn't have any error or warning, especially the warning telling you that eclipse couldn't find the dtd or xml schema for xsl namespace!

Gotchas:
  • Especially if you internet connection is slow, you need to wait a few seconds after opening the xsl before hitting Ctrl+Space because eclipse is downloading the file from http://www.w3.org/2005/02/schema-for-xslt20.xsd
  • I don't know why because I have to close/reopen the eclipse editor for changes to take place

Technorati tags: xsl eclipse

2 comments:

Anonymous said...

xsi:schemalocation should be xsi:schemaLocation with an uppercase L in "location"
(It won't work if its lowercase)

Abhinandan said...

Thanx for this small but very useful trick.