Monday, August 11, 2014

Use Visual Studio to Test XSLT Snippets for Tridion RTF Fields

Recently I've run into some issues with XML and XSLT, particularly the snippets one can add for applying special formatting on RTF fields.  
These snippets can be accessed by viewing a schema's RTF field, selecting the field, clicking the Edit Formatting Features button and navigating to the last tab on the resulting pop-up, tab called "Filtering XSLT".  



I found it quite helpful to run this fast-as-fast-can-be little validation test to narrow down a particular mishap in XSLT.  Certainly, there are much better and more equipped tools out there such as XMLSpy or <oXygen/> for instance, but in my case, speed was of the essence, and as I was not handling a very complex piece of content or elaborate stylesheet, the following steps zapped some light on right away.

1. Open Visual Studio, for instance VS 2012

 

 
2. Load an XML snippet
     Go to File, Open, File.. and select an XML snippet file, for instance the source/content of an RTF field from Saved from Tridion in a sample XML file.  



3. Load an XSLT snippet
     After loading the XML file, the Visual Studio top menu will change and also show an XML main option.  Go to XML, Start XSLT Debugging.  A window will popup to allow you to select the XSLT stylesheet to process.  Navigate to the location of the XSLT, select the stylesheet and click Open.



4. Test run
     Visual Studio will start processing the two files, applying the XSLT to the XML and then reporting back on progress.  It is also possible to add breakpoints here and run through more carefully, or the opposite, run through without any kind of debugging.  The right hand side window will show the resulting XML, labeled with the stylesheet name and an .XML extension.



5. Look for issues reported in Visual Studio
     Any issues detected will show in the Output window so you can take a look and handle them one by one to work through each.




     The only unfortunate discovery I made on this little inside tool is that loading the XSLT becomes cached and the only way to reload it is by restarting Visual Studio.  If anyone found a way to load it without closing, please post back!

Cheers!