Example: Using XSLT instead of Tcl

The code for your application can be generated using XSLT instead of Tcl.

This example demonstrates how to generate a file with AG using XSL Translator.

Generating a form

Instead of generating 4gl as the template does, we'll generate a per file (Genero form definition file). This example uses a 4rd (report data) file and generate a per form file with formfields corresponding to the 4rd record. We'll add an additional property frmLabel on each record field, which will be displayed to the left of each per file formfield.

  • The new property is added to the 4rd definition in settings.agconf (changes are in bold):
    <File extension="4rd">
     <DynamicProperties>
       <DynamicProperty name="foreignFields" type="FIELDS" label="foreignFields"
        initialValue="" dynamicContent="srcFieldsContent" 
        editorInfo="isDynamic:true" />
       <DynamicProperty name="primaryFields" type="FIELDS" label="primaryFields"
        initialValue="" dynamicContent="dstFieldsContent"
        editorInfo="isDynamic:true" />
       <DynamicProperty name="frmlabel" type="TEXT" label="Label FRM" 
        initialValue="" />
     </DynamicProperties>
     <Items>
      <Item nodeName="Relation" srcProperty="foreignFields"
       dstProperty="primaryFields" dynamicProperties="primaryFields;foreignFields"/>
      <Item nodeName="RecordField" dynamicProperties="frmlabel" />
     </Items>
    </File>
  • The file managedtextform.xsl is created, to describe what is to be generated. This file should be saved to the template directory. The GASDIR environment variable should be defined in the GAS configuration and added to PATH.
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="text" />
      <xsl:template match="/">
    --This is generated by the XSL
    
    DATABASE <xsl:for-each select="//Module"><xsl:value-of select="@databaseName"/>
    </xsl:for-each>
    
    LAYOUT 
    GRID
    {
        <xsl:for-each select="//Fields/Field">
          <xsl:value-of select="DynamicProperties/DynamicProperty[@name='frmlabel']
           /@value"/>:   
           [<xsl:value-of select="@column"/>]
        </xsl:for-each>
    }
    END -- LAYOUT
    
    TABLES <xsl:for-each select="//Record"><xsl:value-of select="@table"/>
     </xsl:for-each>
    
    ATTRIBUTES
           <xsl:for-each select="//Fields/Field">
             <xsl:value-of select="@column"/> = <xsl:value-of select="@table"/>.
             <xsl:value-of select="@column"/>;
           </xsl:for-each>     
    
    END -- ATTRIBUTES
      </xsl:template>
    </xsl:stylesheet>
  • A new project is created and a new A Business Application diagram (4ba) is created and saved to the project.
  • A new 4rd file is added to the project and a record created. The properties for frmlabel are added to the record fields.
  • The 4rd Build Rule is updated to generate a per using xslt.
    <BuildRule 
      additionalDependencies="" 
      commands="$(generate) -depth 0 -ba &quot;$(BAFilePath)&quot;
      &quot;$(InputPath)&quot;;fglxslp -o 
        $(InputDir)/$(InputBaseName)per $(GSTSETUPDIR)/managedTextForm.xsl
        $(InputDir)/$(InputBaseName).xml;" 
      description="4RD Report Data compiler" 
      enabled="true" 
      fileType="application/generostudio-4rd" 
      id="1319189142826"
      intermediateFiles="" 
      outputFiles="$(InputDir)/$(InputBaseName)per "/> 

    The same Build Rule displayed in a Genero Studio dialog:

    Figure: Build Rule


    This figure is a screenshot of the Build Rule displayed.
  • The 4rd is compiled and a per is generated.

The generated form

When the per file is opened and previewed, it looks like this.

Figure: per form


This figure is a screenshot of the per form.