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 Files\Microsoft Visual Studio\Common\MSDev98\AddIns).
  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


  • getting error 'Unknown error trying to toggle'...

    Posted by Legacy on 12/06/2002 12:00am

    Originally posted by: Venkat

    This is a nice idea.
    I followed your instructions and installed it.
    I'm running Visual Studio 6.
    When I type-in some xsl text (a copy-paste of your
    code fragment) and click on the toggle button,
    I get the error message box, "Unknown error trying to toggle'.
    What am I doing wrong ?


  • I just used XSLT !

    Posted by Legacy on 10/07/2002 12:00am

    Originally posted by: Allan Beihl

    I got frustrated with typing xslt syntax in xml.

    SO I created a xslt that takes a similar syntax as yours and converts it to ( and fro ) xsl.

    This works anywhere, with any browser/app that does xsl, without having to call any classes, objects, whatever ....

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • "Security" is the number one issue holding business leaders back from the cloud. But does the reality match the perception? Keeping data close to home, on premises, makes business and IT leaders feel inherently more secure. But the truth is, cloud solutions can offer companies real, tangible security advantages. Before you assume that on-site is the only way to keep data safe, it's worth taking a comprehensive approach to evaluating risks. Doing so can lead to big benefits.

  • Hybrid cloud platforms need to think in terms of sweet spots when it comes to application platform interface (API) integration. Cloud Velocity has taken a unique approach to tight integration with the API sweet spot; enough to support the agility of physical and virtual apps, including multi-tier environments and databases, while reducing capital and operating costs. Read this case study to learn how a global-level Fortune 1000 company was able to deploy an entire 6+ TB Oracle eCommerce stack in Amazon Web …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds