Using the Shorter XSL Syntax Add-In

Environment: VC 6

What Does It Do?

This is an add in for working with XSL and ShoXS. In this age of XML, every second new language is in an XML format, which tends to be very hard to read and requires a lot of keying to conform to the XSL syntax. This code demonstrates how an XML format, in this case XSL, can be converted to another syntax and back by using an add in.

What is ShoXS?

ShoXS is a Shorter XSL Syntax. It is not a new language, just another syntax and this module allows you to toggle between XSL and ShoXS, and back to XSL.

To give you an idea of how it works, when you read in an XSL fragment like this:

<xsl:when test=’$level=1′>
<xsl:value-of select=”$level + 1″/>
<xsl:when test=’$level=2′>
<xsl:value-of select=”$level * 2″/>
<xsl:value-of select=”$level – 2″/>

the add in allows you to toggle to the ShoXS equivalent, which is:

switch {
case ($level=1) {
val($level + 1)
case($level=2) {
val($level * 2)
default {
val($level – 2)

Then, when you want to save it, the add in allows you to toggle back to XSL, so that you can save it and use the XSL with an XSL processor. So, you do not need a special ShoXS (pre-)processor. ShOXS is not only a lot less keying work, but is also a lot better for human consumption.

This is a short conversion table for all mappings defined for ShoXS:

xsl-t syntax ShoXS syntax
xsl:for-each for[](@select) {}
xsl:if if[](@test) {}
xsl:choose switch[] {}
xsl:when case[](@test) {}
xsl:otherwise default[] {}
xsl:template fun[mode & priority atts] @name() {}
xsl:template match[mode & priority atts](@match) {}
xsl:apply-templates apply[non-select atts](@select) {}
xsl:call-template call[] @name {}
xsl:value-of val[](@select)
xsl:variable var[] @name=”@select”{}
xsl:param par[] @name=”@select”{}
xsl:with-param wpar[] @name=”@select”{}
xsl:attribute att @name[] = {}
xsl:text text[] “bla”
<–bla–> /*bla*/ OR //bla

More info on XSL can be found on and more info on ShoXS can be found on

Conversion Code

This is the code that is called to convert XSL to ShoX, and it shows how to get the text from the current active window, pass it to the XSL2ShoXSFilter class for conversion to ShoXS, and replace the text in the current window.

STDMETHODIMP CCommands::ConvertXSL2ShoXS()

  ITextDocument* pTextDocument;
                (IDispatch **)&pTextDocument);
  if (!pTextDocument) {
    return S_OK;

Okay, we have the text document handle now.

  ITextSelection * pTextSelection;
               (IDispatch **)&pTextSelection);
  if (!pTextSelection) {
    return S_OK;

And that gives us the handle to the selection. Let’s get the current line so that we can put the cursor at the same line after conversion.

  long nCurrentLine;
  pTextSelection->get_CurrentLine(& nCurrentLine);

Copy all text from the current window.

  BSTR Text;
  pTextSelection->get_Text( & Text);
  CString sText = (LPCWSTR) Text;

Do the conversion to ShoXS.

  try {
    XSL2ShoXSFilter _XSL2ShoXSFilter;
    sText = _XSL2ShoXSFilter.ConvertStringDefault(sText);
  } catch (CString sMsg)
    return S_OK;
  } catch (FilterException _FilterException) {
    return S_OK;
  } catch (...)
    AfxMessageBox("Unknown error trying to toggle");
    return S_OK;

If we got here, no error occurred and we can replace the text in the current window with the ShoXS text and move the cursor to the right line.

  Text = _bstr_t((LPCTSTR) sText);

  return S_OK;
} // ConvertXSL2ShoXS

ConvertShoXS2XSL is a similar method to convert ShoXS back to XSL.

The actual parsing and conversion takes place in the classes XSL2ShoXSFilter and ShoXS2XSLFilter.


  1. Close MSDEV and copy ShoXSaddin.dll to the MSDEV Addins directory (typically located in C:Program FilesMicrosoft Visual StudioCommonMSDev98AddIns).
  2. Start MSDEV, choose the Tools/Customize menu, and then select the “Add-ins and Macro Files” tab.
  3. Tick the “ShoXS.DSAddin.1” check box and click the close button.

A toolbar should appear now with two buttons: one for toggling from XSL to ShoXS and one from ShoXS to XSL.

To add short cut keys:

  1. Select the Tools/Customize menu and choose the “Keyboard” tab.
  2. Select the “Add-ins” in the Category combobox.
  3. Select ConvertXSL2ShoXS or ConvertShoXS2XSL to assign short cuts to the ShoXS add in functions.

I found it handy to define short cut keys to work in ShoXS, and then have a little macro do the conversion from ShoXS to XSL, save the file, and convert back to ShoXS. A macro can also be used to switch on C++ or HTML syntax coloring and then switch from XSL to ShoXS.


Download demo project – 56 Kb

Download source – 46 Kb

More by Author

Must Read