Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

perform XSLT Transform in intelliJ on files with other extension (e.g. DITA, HTML)

As said in title, I want to be able to do XML transformation with XSLT 2.0 in intelliJ.

  • I know IntelliJ can do transformation, but it only recognize .xml files.
  • I want to transform (in essence) XML files with .dita, or .html extension
  • I use Windows 7.

I know Oxygen can do the transformation too, but it's too expensive. So that's not an option for me.

Does anyone know any plugin? configuration or anyway that can make intelliJ transform on XML files with different extensions?

like image 578
Anna Morning Avatar asked Mar 24 '23 11:03

Anna Morning


1 Answers

Intellij supports transformation with XSLT. It provides XSLT 1.0 transfomations out of the box, but XSLT 2.0 transformations require a bit of configuration. The details are available on the jetbrains website here, but essentially, you have to enable the "XPathView + XSLT Support" plugin. This plugin is bundled with Intellij and enabled by default so you should be good to go out of the box for XSLT 1.0. You can just open your stylesheet file in the editor and right click inside the file, you'll get a drop-down with one of the options being "Run .xsl" if you click this, then you can specify the source document and whether the output should go to the console or to a file and then intellij will run your stylesheet and send the output to where you chose.

For XSLT 2.0 the additional configuration necessary is to add an XSLT processor that supports XSLT 2.0 to the classpath. The reason you need to do this is because the XSLT processor that comes standard with the JDK is Apache Xalan and this doesn't support XSLT 2.0. Saxon HE 9 is a free XSLT processor that supports XSLT 2.0. You can download the jar from the project site here and then add it to your project by opening the project structure dialog, going to the Module settings and opening the dependencies tab. Add the jar as a new dependency and Make sure it is at the top of the list of dependencies, above the JDK. Intellij will now use this XSLT processor instead of the one in the JDK to do the transformations.

FYI, you can also add Saxon as a dependency using maven and then it will automatically appear in the dependencies tab and you will just need to make sure to move it to the top of the list

like image 75
Machaba Avatar answered Apr 05 '23 19:04

Machaba