Mixing USoft application data into an XSLT transformation

Previous Next

When calling USXSL.APPLY or USXSL.APPLY2FILE, you can mix USoft application data into the transformation:

By including one or more INVOKE statements into the input XML.

By including one or more INVOKE statements into the XSLT stylesheet.

INVOKE statements in the input XML

You can get USoft application data into the input XML document at the time when you pass this XML document to be processed by USXSL.APPLY or USXSL.APPLY2FILE.

Example

This example outputs a combination of customer data and employee data to a single output file. The effect of the XSLT transformation in this case is void: it simply copies the input XML to the output tree and writes that output to the file system.

The output XML has the same format as the output of XML.MultiExportTables. This format is described in detail in USoft XML Format.

SELECT usxsl.apply2file
(
   '<?usoft-xml version="1.0" action="multi-tables-import"?>
   <MultiImport>
   '  ||
     TO_CLOB(( INVOKE xml.export WITH SELECT * FROM CUSTOMER WHERE full_name  like '%'))  ||
     TO_CLOB(( INVOKE xml.export WITH SELECT * FROM EMPLOYEE WHERE emp_no < 100))  ||
   '
   </MultiImport>'
,  '%SYSTEMDIR%/xsl/util/copy.xsl'
,  'c:\temp\myexport.xml'
)

INVOKE statements in the XSLT stylesheet

You can get USoft application data into the XSLT stylesheet document at the time when you pass this XML document to be processed by USXSL.APPLY or USXSL.APPLY2FILE.

Example

This example transforms an input file with TOUR data for tours to Australia destinations. The transformation compares this data against older TOUR data in the current repository. Imagine that the input XML is a list of TOUR data from a NEWER version of the tour catalogue, and that the transformation is run against a repository containing an OLDER version of the tour catalogue.

The output XML is a list of destinations with, for each destination, a STATUS attribute that is

"New" if the TOUR data exists in the input XML but not in the repository.

"Existing" if the TOUR data exists in both the input XML and the repository.

The transformation call is:

SELECT usxsl.apply
(
     'c:\temp\old_tours.xml'
,    'c:\temp\comparison.xsl'
,    'string:country'
,    'AUSTRALIA'
)

The XSLT stylesheet is:

<?xml version="1.0" encoding="windows-1252"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="no"/>
<xsl:param name="country"/>
 
<xsl:variable name="existing">invoke xml.export with select * from tour where country = '<xsl:value-of select="$country"/>'</xsl:variable>
<xsl:variable name="doc-existing" select="document($existing)"/>
 
<xsl:template match="/Tours">
  <Catalogue documentName="Catalogue">
     <xsl:apply-templates select="*"/>
  </Catalogue>
</xsl:template>
 
<xsl:template match="*">
<xsl:variable name="this" select="@DESTINATION"/>
<xsl:variable name="exist" select="$doc-existing/*/TOUR[@DESTINATION=$this]"/>
  <TOUR>
    <xsl:attribute name="DESTINATION" select="$this"/>
    <xsl:attribute name="STATUS">
      <xsl:choose>
        <xsl:when test="$exist">Existing</xsl:when>
        <xsl:otherwise>New</xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>       
  </TOUR>
</xsl:template>
 
</xsl:stylesheet>

 

See also

USXSL internal component