Blog Pro de Jean-Baptiste HEREN - Tag - cognos 8 Notes d'un consultant Freelance en Informatique 2015-11-03T21:34:19+01:00 JB HEREN urn:md5:e39389b5ec134d99645112fce3d957df Dotclear model.xml documentation in cognos 8 with xslt urn:md5:88da78e37f99ab7b588f608cb2ed9ca9 2011-03-30T06:56:00+02:00 2011-04-07T15:16:44+02:00 Jean-Baptiste Heren Décisionnel cognos 8xmlxslt <p>In one of my recent projects, I had to build an automatic documentation builded on top of a database, using <a href="http://blog.jbheren.com/tag/cognos%208">cognos 8</a> reporting itself.</p> <p>This article covers the way I could extract technical informations using the Cognos Framework manager project model.xml file.</p> <h3>1- Build xsl files</h3> <p>The XSLT language is used to define the way an xml should be displayed. This means you can select any parts of teh xml, based on his structure and build the output you want.</p> <h4>Defining the stylesheet</h4> <p>Here is an example witch displays a list of Query Subjects extracted from your project :</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt; &lt;xsl:template match=&quot;/&quot;&gt; &lt;html&gt; &lt;body&gt; &lt;h1&gt;Query Subjects&lt;/h1&gt; &lt;table border=&quot;1&quot;&gt; &lt;tr&gt; &lt;td&gt;&lt;h2&gt;refObj&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Source Type&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Namespace&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Folder&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;Query Subject&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;dataSource&lt;/h2&gt;&lt;/td&gt; &lt;td&gt;&lt;h2&gt;sql&lt;/h2&gt;&lt;/td&gt; &lt;/tr&gt; &lt;xsl:for-each select=&quot;//querySubject[@status = 'valid']&quot;&gt; &lt;tr&gt; &lt;td&gt;&lt;p&gt;[&lt;xsl:value-of select=&quot;../../name&quot;/&gt;].[&lt;xsl:value-of select=&quot;name&quot;/&gt;]&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;definition/dbQuery/tableType&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;../../name&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;../name&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;definition/dbQuery/sources/dataSourceRef&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;td&gt;&lt;p&gt;&lt;xsl:value-of select=&quot;definition/dbQuery/sql&quot;/&gt;&lt;/p&gt;&lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <h4>Applying the stylesheet</h4> <p>During the XSL development, we need to test the output of our xsl applyend to our model.xml "live". To do this, we will :</p> <p>- Add the stylesheed definition to your <strong>local copy</strong> of model.xml, like that :</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;modelspecs.xsl&quot;?&gt; &lt;project&gt; </pre> <p>- Open your xml in Internet Explorer or any other modern navigator and see the output.</p> <h3>2- Automatic processing</h3> <p>For my specific need, I wanted to generate automatic data files from different project's model.xml, to be used as source for some DTS.</p> <p>Here are four examples of XSL files extracting different informations. Of course, we can also build one single xml file containing all the informations :</p> <p>- cubes definitions : This example outputs pure text to be used as a CVS source in SSIS.</p> <pre>[XML] &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt;&lt;xsl:strip-space elements=&quot;*&quot;/&gt;&lt;xsl:output method=&quot;text&quot;/&gt;&lt;xsl:template match=&quot;/&quot;&gt;refObj;Source type &lt;xsl:for-each select=&quot;//namespace&quot;&gt; &lt;xsl:if test=&quot;string-length(property[@name = 'dynamicContent']) != 0&quot;&gt;[&lt;xsl:value-of select=&quot;name&quot;/&gt;];Cube &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <p>- Query Subjects &amp; SQL : This example outputs simple xml file to be used as a XML source in SSIS.</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt; &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; cdata-section-elements=&quot;sql&quot;/&gt; &lt;xsl:template match=&quot;/&quot;&gt; &lt;xsl:element name=&quot;root&quot;&gt; &lt;xsl:for-each select=&quot;//querySubject[@status = 'valid']&quot;&gt; &lt;xsl:element name=&quot;querySubjects&quot;&gt; &lt;xsl:element name=&quot;refObj&quot;&gt;[&lt;xsl:value-of select=&quot;../../name&quot;/&gt;].[&lt;xsl:value-of select=&quot;name&quot;/&gt;]&lt;/xsl:element&gt; &lt;xsl:element name=&quot;sourceType&quot;&gt;&lt;xsl:value-of select=&quot;definition/dbQuery/tableType&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;namespace&quot;&gt;&lt;xsl:value-of select=&quot;../../name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;folder&quot;&gt;&lt;xsl:value-of select=&quot;../name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;querySubject&quot;&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;dataSource&quot;&gt;&lt;xsl:value-of select=&quot;definition/dbQuery/sources/dataSourceRef&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;sql&quot;&gt;&lt;xsl:value-of disable-output-escaping=&quot;yes&quot; select=&quot;definition/dbQuery/sql&quot;/&gt;&lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <p>- Query Subjects &amp; Query items detail : This example outputs simple xml file to be used as a XML source in SSIS.</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt; &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; cdata-section-elements=&quot;sql&quot;/&gt; &lt;xsl:template match=&quot;/&quot;&gt; &lt;xsl:element name=&quot;root&quot;&gt; &lt;xsl:for-each select=&quot;//querySubject[@status = 'valid']/queryItem&quot;&gt; &lt;xsl:element name=&quot;QueryItems&quot;&gt; &lt;xsl:element name=&quot;refObj&quot;&gt;[&lt;xsl:value-of select=&quot;../../../name&quot;/&gt;].[&lt;xsl:value-of select=&quot;../name&quot;/&gt;].[&lt;xsl:value-of select=&quot;name&quot;/&gt;]&lt;/xsl:element&gt; &lt;xsl:element name=&quot;parentRefObj&quot;&gt;[&lt;xsl:value-of select=&quot;../../../name&quot;/&gt;].[&lt;xsl:value-of select=&quot;../name&quot;/&gt;]&lt;/xsl:element&gt; &lt;xsl:element name=&quot;QueryItem&quot;&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <p>- Framework Packages Definition and contents : This example outputs simple xml file to be used as a XML source in SSIS.</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt; &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; cdata-section-elements=&quot;sql&quot;/&gt; &lt;xsl:template match=&quot;/&quot;&gt; &lt;xsl:element name=&quot;root&quot;&gt; &lt;xsl:for-each select=&quot;//securityView/definition/set/refobj&quot;&gt; &lt;xsl:element name=&quot;packages&quot;&gt; &lt;xsl:element name=&quot;packageName&quot;&gt;&lt;xsl:value-of select=&quot;../../../name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;contentRefObj&quot;&gt;&lt;xsl:value-of select=&quot;.&quot;/&gt;&lt;/xsl:element&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <p>- Framework Dimensions Definitions and contents : This example outputs simple xml file to be used as a XML source in SSIS.</p> <pre>[XML] &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;xsl:stylesheet version=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;&gt; &lt;xsl:output method=&quot;xml&quot; version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; indent=&quot;yes&quot; cdata-section-elements=&quot;sql&quot;/&gt; &lt;xsl:template match=&quot;/&quot;&gt; &lt;xsl:element name=&quot;root&quot;&gt; &lt;xsl:for-each select=&quot;//dimension[@status = 'valid']&quot;&gt; &lt;xsl:element name=&quot;dimensions&quot;&gt; &lt;xsl:element name=&quot;namespace&quot;&gt;&lt;xsl:value-of select=&quot;../name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;dimension&quot;&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:element name=&quot;modelQuery&quot;&gt;&lt;xsl:value-of select=&quot;definition/modelQuery/sql&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:for-each select=&quot;hierarchy&quot;&gt; &lt;xsl:element name=&quot;hierarchy&quot;&gt; &lt;xsl:element name=&quot;name&quot;&gt;&lt;xsl:value-of select=&quot;name&quot;/&gt;&lt;/xsl:element&gt; &lt;xsl:for-each select=&quot;.//refobj&quot;&gt; &lt;xsl:element name=&quot;refobject&quot;&gt;&lt;xsl:value-of select=&quot;.&quot;/&gt;&lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:for-each&gt; &lt;/xsl:element&gt; &lt;/xsl:template&gt;&lt;/xsl:stylesheet&gt; </pre> <p>Command line xsl transformation is possible using the xslproc program :</p> <pre>[script] xsltproc mysxmltocsv.xsl model.xml &gt; doc.csv or xsltproc mysxmltoxml.xsl model.xml &gt; doc.xml </pre> <p>the unix tool xmlproc is also available in the libxslt binary package for windows at following address : ftp://ftp.zlatkovic.com/libxml/</p> <h3>3- Conclusion</h3> <p>Hope it will help someone, it's quite hard to find informations on how to dicument Cognos. if anyone has anything to share, I am still interested ^^.</p>