Understand XSLT transformations

The XSLT document specifies how to change an XML document's structure. Inspire uses an XSLT processor to use the rules defined in the XSLT to change an XML document into a differently-formatted XML document.

To transform an XML component, Inspire calls a processor that requires as input:

  • An existing, unlocked XML component in Inspire
  • An XSLT in Inspire (stored as a binary component) that defines how to re-format an XML component

The result is that the XML code in the original file is saved with new XML code.

  • No new component is created.
  • If you want to see the original XML, you must restore the transformed component.

In Inspire, this XSLT transformation only transforms an XML document into an updated XML document. If you want to transform XML into another format, such as HTML or PDF, you must publish it and select the appropriate publish configuration. Publish your content.

For example, you could have a form that customers use to register their product, and a form for employees to manage the customer database and store inventory. They contain the same data fields, but look slightly different and the data is in a different order.

The data enters your system when a customer registers their product. It could be a simple XML component similar to the following:

Customer form XML file
<?xml version="1.0" ?>
<customers>
  <customer ID="0794e">
    <first-name>John</first-name>
    <family-name>Smith</family-name>
    <product>DSLR_Camera</product>
  </customer ID>
<customer ID="2345h">
    <first-name>Jane</first-name>
    <family-name>Doe</family-name>
    <product>DSLR_Lens</product>
  </customer ID>
</customers>

After the data is in your system, you want to add it to your store customer database and keep track of the inventory you've sold.

To see only the customer data you would create an XSLT similar the following:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="xml" indent="yes"/>

  <xsl:template match="/customers">
    <root>
      <xsl:apply-templates select="customer"/>
    </root>
  </xsl:template>

  <xsl:template match="customer">
    <customer ID ="{@ID}">
      <xsl:value-of select="first-name"/>
    </name>
  </xsl:template>

</xsl:stylesheet>

Inspire uses a processor to transform the original XML data using the XSLT.

  • The basic processing paradigm is pattern matching.
  • Template rules only define how to handle a node matching a particular XPath-like pattern, if one exists.
  • The contents of the templates contain functional expressions that directly represent their evaluated form.

The next time you open the customer XML form, it now exists as the store form, similar to the

following:

Store form XML file
<?xml version="1.0" encoding="UTF-8"?>
<root>
  <customer ID="0794e">John</first-name>
  <customer ID="2345h">Jane</first-name>
</root>

You could also create another XSLT to pull out just the customer ID and the Product to create a store inventory form.