15.5 XDQL Example in XSL Stylesheet

Let us take a simple example to understand how XDQL is used to fetch Docbase data dynamically within Presentation files (XSL stylesheets).

The following sample template file will be transformed via an XSL stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<ROOTTAG>
<TITLEOFPAGE/>
<SHORTDESC/>
</ROOTTAG>

The XSL stylesheet in this example will be used to create an HTML transformation of the above template XML file. The transformed file (HTML web rendition) will display the name of the content file (object_name attribute) that is created using the above template.

Create an XSL file (as shown in figures 15.16 and 15.17) and import it within the Docbase at the following location: /Site Manager/Presentations/Editor/Custom_Presentations.

15.5 XDQL Example in XSL Stylesheet

Figure 15.16: Sample XSL file using XDQL

15.5 XDQL Example in XSL Stylesheet

15.17: Sample XSL file using XDQL—continued

We will now discuss the anatomy of the above XSL stylesheet:

  • Namespaces: Add the following Java and Xalan namespaces in the <xsl:stylesheet> tag of the presentation file. For example:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:java="http://xml.apache.org/xslt/java" xmlns:xalan="http://xml.apache.org/xalan" exclude-result-prefixes= "xalan java fo">
  • Parameters: Declare the parameters that are passed by the system to the stylesheet. For example:
<xsl:param name="DMS_SESSION_ID" select="'default value'"/>
<xsl:param name="DMS_INPUT_OBJECT_ID"/>

DMS_SESSION_ID is a reference to the current Docbase session and DMS_INPUT_OBJECT_ID is a reference to the current object ID (r_object_id attribute).

  • XDQL classes: Define an XSL template using the <xsl:template> tag to instantiate the DfXmlQuery() class, pass XDQL parameters, and execute DQL queries from within the XSL stylesheet. For example:
<xsl:template name="XDQL">
<xsl:param name="dql"/>

<xsl:param name="roottag" select="string('xdql')"/>
<xsl:param name="UpperTags" select="string('false')"/>
<xsl:param name="MaxRows" select="10"/>
<xsl:param name="RowIDAttrName" select="ID"/>
<xsl:param name="RowsetTag" select="Row"/>
<xsl:param name="UseGivenCaseTagNames" select="true"/>
<xsl:param name="UseNullAttrIndicator" select="false"/>
<xsl:variable name="xdql" select="java:com.documentum.xml.xdql.DfXmlQuery.new()"/>
<xsl:variable name="init" select="java:init($xdql)"/>
<xsl:variable name="param" select="java:setDql($xdql,$dql)"/>
<xsl:variable name="param1" select="java:setRootNode($xdql,$roottag)"/>
<xsl:variable name="param3" select="java:includeContent($xdql,false())"/>
<xsl:variable name="setContentEncoding" select="java:setContentEncoding($xdql,string('dom'))"/>
<xsl:variable name="setContentFormat" select="java:setContentFormat($xdql,string('xml'))"/>
<xsl:variable name="execute" select="java:execute($xdql, 'DF_READ_QUERY', $DMS_SESSION_ID)"/>
<xsl:variable name="queryresult" select="java:getXMLDOM($xdql)"/>
<xsl:copy-of select="$queryresult"/>
</xsl:template>

It is advisable to go through the DFC Javadocs of the com.documentum.xml.xdql.IDfXmlQuery interface to understand the arguments and return types of the numerous methods used in the <xsl:template name="XDQL"> shown above.

Variables:
Define a variable to store the DQL query to be invoked from within the stylesheet.
For example:
<xsl:variable name = "dqlQuery">select r_object_id, object_name from dm_document where r_object_id = '<xsl:value-of select="$DMS_INPUT_OBJECT_ID"/>'</xsl:variable>

This code stores the DQL query string used to fetch the object ID (r_object_id attribute) and the file name (object_name attribute) of the current content file (i.e. whose object ID matches the current object ID: DMS_INPUT_OBJECT_ID).

Also, define a variable to store the results of the above DQL query by calling the pre-defined XDQL template and passing the DQL query string to it. For example:

<xsl:variable name = "query_results">

<xsl:call-template name="XDQL">
<xsl:with-param name="dql" select="string($dqlQuery)"/>
</xsl:call-template>
</xsl:variable>

Once you have the query results saved in a variable, iterate through it, retrieve the required attribute (object_name in our case) and save it in a variable.

For example:
<xsl:variable name="ObjectName">

<xsl:for-each select="xalan:nodeset($query_results)/xdql/object">
<xsl:value-of select="object_name"/>
</xsl:for-each>
</xsl:variable>

This is all that needs to be taken care of while using XDQL within XSL stylesheets in Web Publisher. In our example, displaying the content file's name (object_name attribute) is as simple as accessing the value of the ObjectName variable. For example:

<!-- Displaying the name of the file (object_name attribute) -->
<td><b><u><xsl:value-of select="$ObjectName"/></u></b></td>

Note that by using $(variableName), the system substitutes the value contained in the variable at run time.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.166.241