Creating XSLTs Without The Visual Designer

Introduction

While the Visual Designer offers a simple way for non-technical users to create forms for use within EditLive! for XML, however, developers who are familiar with XSLT may also create forms by hand to take advantage of the full power and flexibility of XSLT. EditLive! for XML has been designed with this in mind and supports most XSLTs without change. However, to take full advantage of EditLive! for XML there are some simple things to keep in mind and a number of Ephox extensions to XSLT which provide control over the additional features provided by EditLive! for XML. All the Ephox extensions to XSLT are in a separate namespace and will be ignored by standard XSLT processors. It is therefore possible to take full advantage of the features of EditLive! for XML and still use the same XSLT outside of EditLive! for XML.

Design Considerations

Context Node

The context node is a key concept in writing XSLTs and this is particularly true with EditLive! for XML. Nearly all of the EditLive! for XML's features utilize the context node in some way. When developing an XSLT for use with EditLive! for XML the XSLT should be structured so that the context node is relevant for each part of the XSLT. For instance, when creating the output for an optional element it is better to use:

<?xml version="1.0"?>
<xs:stylesheet version="1.0"
  xmlns:xs="http://www.w3.org/1999/XSL/Transform"
  xmlns:my="http://www.ephox.com/product/editliveforxml/document/Untitled">

  <xs:template match="/">
    <html>
      <head />
      <body>
        <!-- The context node is now / -->
        <p>
        <xs:apply-templates select="/my:Untitled/my:optionalElement" />
        </p>
      </body>
    </html>
  </xs:template>

  <xs:template match="my:optionalElement">
    <!-- The context node is now my:optionalElement -->
    <xs:value-of select="." />
  </xs:template>
</xs:stylesheet>

as opposed to:

<?xml version="1.0"?>
<xs:stylesheet version="1.0"
  xmlns:xs="http://www.w3.org/1999/XSL/Transform"
  xmlns:my="http://www.ephox.com/product/editliveforxml/document/Untitled">

  <xs:template match="/">
    <html>
      <head />
      <body>
        <!-- The context node is now / -->
        <p>
        <xs:value-of select="/my:Untitled/my:optionalElement" />
        </p>
      </body>
    </html>
  </xs:template>
</xs:stylesheet>

In a standard XSLT processor both examples produce the same output, but in EditLive! for XML the first example will automatically provide a button that allows the user to insert the optional element whereas the second example assumes the element always exists and provides a text field. For more information on how buttons are added to the EditLive! for XML interface please see the section on Automatically Added Buttons.

Imports and Includes

When including data from files other than the XML document being edited, it is important to mark the data as read only as any changes made by the user will be lost. This occurs because only the XML document loaded into the editor is returned and thus changes to other files will be lost. The ephox:readonly attribute can be used to indicate that data is read only.

When specifying relative URLs for imports and includes, be aware that the XSLT or XSD must have been loaded from an URL rather than being passed into EditLive! for XML as a string so that there is a base URL to resolve it against. It is recommended that absolute URLs be used whenever possible to avoid confusion.

XPath Expressions

EditLive! for XML includes the ability to dynamically re-evaluate XPath expressions as the user makes changes to the XML document. While standard XPath expressions will work as expected in most cases there are some important considerations users of XPath should keep in mind. The dynamic XPath engine in EditLive! for XML cannot evaluate XSLT variables, therefore any XPath expressions that reference XSLT variables will be statically displayed instead of dynamically updating. XSLT designers can provide an ephox:button with an action of updateView to allow the user to re-evaluate the expression.