Import Permanent link for this heading

Simple Import ExamplePermanent link for this heading

Based on a source XML document objects are created or updated. The following example has already been used in chapter “Getting Started” to import two folders.

Example

import.xsl

<?xml version="1.0" encoding="UTF-8" ?>
<!-- folders are imported and the name and external key are set -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:sys="http://www.fabasoft.com/components/COOSYSTEM@1.1"
xmlns:desk="http://www.fabasoft.com/components/COODESK@1.1">
  <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
    omit-xml-declaration="no"/>
  <xsl:template match="/">
    <xsl:apply-templates select="/root/folder"/>
  </xsl:template>
  <xsl:template match="folder">
    <sys:Value search="sys:objexternalkey" searchobjclass="desk:Folder"
     create="desk:Folder" match="literal" >
      <sys:objname select="name"/>
      <sys:objexternalkey select="externalkey"/>
    </sys:Value>
  </xsl:template>
</xsl:stylesheet>

import.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- two folders should be imported -->
<root>
  <folder>
    <name>Projects</name>
    <externalkey>projects</externalkey>
  </folder>
  <folder>
    <name>Year 2011</name>
    <externalkey>year2011</externalkey>
  </folder>
</root>

Explanation:

  • xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:sys="http://www.fabasoft.com/components/COOSYSTEM@1.1"

    xmlns:desk="http://www.fabasoft.com/components/COODESK@1.1"

    Define the needed namespaces. xsl and sys are mandatory. In this case also the prefix desk is defined because the component object COODESK@1.1:Folder belongs to COODESK@1.1.
  • <xsl:template match="/">
      <xsl:apply-templates select="/root/folder"/>

    </xsl:template>

    Apply templates to all folder nodes in import.xml.
  • <xsl:template match="folder">
      <sys:Value search="sys:objexternalkey" searchobjclass="desk:Folder"

        create="desk:Folder" match="literal" >

        <sys:objname select="name"/>

        <sys:objexternalkey select="externalkey"/>

      </sys:Value>

    </xsl:template>

    For each folder a corresponding object with the same objexternalkey is searched. If no folder is found a new one is created. The properties objname and objexternalkey are set based on data in the import.xml. More information about sys:Value can be found in chapter “sys:Value”.

Note: In most cases it makes sense to work with the property COOSYSTEM@1.1:objexternalkey to identify imported and exported objects.

sys:ValuePermanent link for this heading

The sys:Value block is used as starting point to redirect the output to a Fabasoft Folio object. Instead of writing to the meta XML file, properties of created or found objects are set.

Searching for Fabasoft Folio ObjectsPermanent link for this heading

sys:Value is used to search for objects in Fabasoft Folio that match the defined criteria. If no object is found a new one is created.

Syntax

<sys:Value search="[prop1] [prop2] [...]" searchobjclass="[objclass]"
  create="
[objclass]" match="[literal|pattern]">

Explanation:

  • search
    Defines properties to restrict the search. If several properties are defined they are combined with AND. The properties used for search have to be defined within the sys:Value block (e.g. <sys:objexternalkey select="externalkey"/>).
  • searchobjclass
    Defines the object class to be searched for.
  • create
    Defines the object class that is used to create new objects if no object matches the search criteria.
  • match
    May have two values: literal and pattern.
    literal is translated to = in the Fabasoft app.ducx Query Language.
    pattern is translated to LIKE in the Fabasoft app.ducx Query Language.

Example

<sys:Value search="sys:objexternalkey" searchobjclass="desk:Folder"
  create="desk:Folder" match="literal" >

  <sys:objname select="name"/>
  <sys:objexternalkey select="externalkey"/>
</sys:Value>

// the resulting query translated in Fabasoft app.ducx Query Language
SELECT * FROM COODESK@1.1:Folder WHERE .COOSYSTEM@1.1:objexternalkey = 'projects'

<sys:Value search="sys:objexternalkey sys:objname" searchobjclass="desk:Folder"
  create="desk:Folder" match="pattern" >

  <sys:objname select="name"/>
  <sys:objexternalkey select="externalkey"/>
</sys:Value>

// the resulting query translated in Fabasoft app.ducx Query Language
SELECT * FROM COODESK@1.1:Folder WHERE .COOSYSTEM@1.1:objexternalkey LIKE 'projects' AND .COOSYSTEM@1.1:objname LIKE 'Projects'

Selecting Fabasoft Folio ObjectsPermanent link for this heading

Beside searching for objects, objects can also be selected using sys:Value.

Syntax

<sys:Value select="sys:GetObject('[objaddress]')">

Explanation:

  • select
    Has to return a valid Fabasoft Folio object.

Example

<sys:Value select="sys:GetObject('COO.1.506.1.1127')">
  <sys:objname select="name"/>
  <sys:objexternalkey select="externalkey"/>
</sys:Value>

Setting Values of Object PropertiesPermanent link for this heading

There are several types of properties and several ways to set a value.

Note:

  • Properties that are updated with invalid values are set empty.
  • Properties can be set empty when using empty values in the import XML file (e.g. <done></done>).

Ways to Set a ValuePermanent link for this heading

Static value:

The tag consists of the name of the property to be set.

Example

<sys:objname>My Name</sys:objname>

Value from an XML document:

The tag consists of the name of the property to be set and a select attribute. In the select attribute the XPath to value in the source XML is defined.

Example

<sys:objname select="name"/>

Value evaluated with a Fabasoft app.ducx Expression:

The value is evaluated with the sys:Evaluate function. Make sure to use disable-output-escaping="yes", because the output should be as it is without modification.

Example

<sys:objname select="sys:Evaluate('&quot;Simple evaluated name&quot;')" disable-output-escaping="yes"/>

<sys:objname select="sys:Evaluate('::key1')" disable-output-escaping="yes"/>

Value evaluated with a Fabasoft app.ducx Expression Using an XML Node:

The value is evaluated with the sys:Evaluate function with these parameters:

sys:Evaluate('[arbitrary expression]', [arbitrary xpath], ., 'name')"

All child nodes of the node defined by the arbitrary XPath are available in the global scope and can be accessed with the node’s name. Make sure to use disable-output-escaping="yes", because the output should be as it is without modification.

Example

// if the current node is currencysymbol you have access to ::value and ::symbol
// in this case it is used to evaluate the corresponding integer value of EUR
// because the enumeration can only be set with the integer value

<sys:currsymbol select="#CurrencySymbol.typeenumvalues[typeenumref==::symbol].
  typeenumval',./*,.,'name')"
disable-output-escaping="yes" />

import.xml

<currencysymbol>
  <value>203.56</value>
  <symbol>EUR</symbol>
</currencysymbol>

Data TypesPermanent link for this heading

The following example provides an overview on how to set values depending on the data type of the properties.

Example

app.ducx Object Model Language

objmodel TRANS@1.506
{

  
import COOSYSTEM@1.1;
  
import COOXML@1.1;

  enum EnumTest {
    ET_ENTRY1,

    ET_ENTRY2,

    ET_ENTRY3

  }

  struct CompoundTest {
    
string ctprop1;
    
string ctprop2;
  }  

  // defines a test class with several properties of different data types
  class Test : BasicObject {
    string str;
    
integer int;
    
float flo;
    
boolean boo;
    
datetime dt;
    Object op;

    EnumTest et;

    CompoundTest ct;

    currency curr;

    currency currsymb;

    Object[] opl;

  }

}

import.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:sys="http://www.fabasoft.com/components/COOSYSTEM@1.1"
  xmlns:t="http://www.fabasoft.com/components/TRANS@1.506">

  <xsl:output method="xml" version="1.0" encoding="UTF-8"
    indent="yes" omit-xml-declaration="no" />

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

  <xsl:template match="object">
    <sys:Value search="sys:objexternalkey" searchobjclass="t:Test"
      create="t:Test" match="literal">

      <!-- shows how to set values of properties with different data types -->
      <sys:objname select="name" />
      <sys:objexternalkey select="externalkey" />
      <t:str select="string" />
     <t:int select="integer" />
      <t:flo select="float" />
     <t:boo select="boolean" />
      <t:dt select="datetime" />
      <t:op select="sys:Evaluate('coort.GetObject(::this)', objectpointer)" />
      <t:et select="enumeration" />

      <t:ct>
        <t:ctprop1 select="compound/value1" />
        <t:ctprop2 select="compound/value2" />
      </t:ct>

      <t:curr>
        <sys:currvalue select="currency/value" />
        <sys:currsymbol select="currency/symbol" />
      </t:curr>
      <t:currsymb>
        <sys:currvalue select="currencysymbol/value" />
        <sys:currsymbol select="sys:Evaluate('#CurrencySymbol.typeenumvalues
          [typeenumref==::symbol].typeenumval',./currencysymbol/*,.,'name')"
          disable-output-escaping="yes" />
      </t:currsymb>

      <xsl:for-each select="list/value">
        <t:opl select="sys:Evaluate('coort.GetObject(::this)', .)" />
      </xsl:for-each>

    </sys:Value>
  </xsl:template>
</xsl:stylesheet>

import.xml

<?xml version="1.0" encoding="utf-8"?>
<root>
  <object>
    <name>Data Types</name>
    <externalkey>datatypes5</externalkey>
    <string>test</string>
    <integer>79</integer>
    <float>50.6</float>
    <boolean>1</boolean>
    <datetime>2012-08-11T10:12:13</datetime>
    <objectpointer>COO.1.506.1.1001242</objectpointer>
    <enumeration>2</enumeration>
    <compound>
      <value1>Project</value1>
      <value2>097845</value2>
    </compound>
    <currency>
      <value>500</value>
      <symbol>1</symbol>
    </currency>
    <currencysymbol>
      <value>203.56</value>
      <symbol>EUR</symbol>
    </currencysymbol>
    <list>
     <value>COO.1.506.1.1001242</value>
     <value>COO.1.506.1.1001241</value>
    </list>
  </object>
</root>