# Tuesday, September 18, 2012

Presidential Elections, Processing Historical Data

We are approaching a new presidential election here in the US, and many are very excited to follow the evolving political trends.   The election results are very important public records which allow anyone to verify the transparency of the core process for any modern democracy.

In this article we explore how to extract election historical data, stored in a variety of data sources and use Stylus Studio in a creative manner.

We start with the 2004 election result which we have found in the text format. In the following screenshot, we see the raw flat file.



We can now convert the data using the Convert to XML module which allows us to generate an XML document with a few clicks. We use the first line in the file to create the element names.  The preview window shows the conversion result.


Once the data  is converted to XML we can open the document using the Stylus Studio XML editor; switching  to the Grid view allows us to easily sort the grid content using any of the column headers (right click-> Sort)


Now that we have full control on the data for the 2004 election results, we can move to the 2008 election. This data has been stored in a relation database; the simple diagram below illustrates the relationship between the “States” table and the “Election2008” table.


Our goal is to query the database and to generate an XML document which will have a similar structure to the previously converted flat file. For this task we are going to use the DataDirect XQuery engine which allows for joining the table’s data and returning an XML document.

In the following screenshot you can see how the XQuery mapping tool has been used to build a “for” statement and the collection function calls are used to access the database tables. The equal operator matches the records where the StateID is the same.

The preview window which captures the query result has been undocked to reduce the real-estate.



If you are wondering how such an approach can scale with a large database, take a peek at the query plan to discover what happens under the cover. The following screenshot reveals that the query has been translated into a SQL SELECT and it runs as fast as native SQL query.


In the next step, we build a report which compares the results between the two presidential candidates  state by state. The background color indicates the party who won the state.



The final step consists of chaining together what we have designed in a pipeline, which can be executed as a single unit.



We hope you enjoyed reading this article. If you have any questions, do not hesitate to contact us.

You can download the Project Zip file by clicking here.

- Stylus Studio Team

Description:<a href= Technical Support
Description: Description: http://www.stylusstudio.com/images/build-dahsboards-xslt/image016.gif Follow us on Twitter
Description: Description: http://www.stylusstudio.com/images/build-dahsboards-xslt/image017.gif Connect on Facebook 

posted on Tuesday, September 18, 2012 2:51:38 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [1] Trackback
# Thursday, August 16, 2012

Extending XSLT with Java and C#

The world is not perfect. If it were, all data you have to process would be in XML and the only transformation language you would have to learn would XSLT. Because the world is not perfect, sometimes you have to find ways to bridge different systems that were not designed to work together.

The most popular XSLT processors have been designed, from the very first release, to take advantage of the framework on which they run; for example Apache Xalan-J and Saxon allow calling Java functions. In this article, we will explore a variety of techniques for invoking native code from XSLT to extend the language beyond its capabilities.

The first example demonstrates how to leverage the Date and Time formatting capabilities available in the Java platform. Imagine you have a list of dates in an XML file that you have to display in a HTML page using different formats. The following screenshot shows a simple XML file with three repeating elements called “date”, each has three attributes: “year”, “month” and “day”.

A separate XML document has the date formats. Each element “entry” has an attribute format with the “picture string” which describes how and which part of the date should be displayed.

Our goal is to merge the information from the two XML documents into a simple HTML page which will display each date in multiple formats.

XSLT 1.0 lacks date and time formatting functions but, Java provides two classes: java.util.Calendar and java.text.SimpleDateFormat, which solve our problem. We just need to create a Java class with a single public static method that will be called from our XSLT transformation. In the following screenshot, we see the Stylus Studio Java extension editor which features syntax coloring, background syntax checking and integrated Java compiler invocation.

When designing Java extension functions for XSLT, it is important to remember that the function parameter type has to be compatible with the processor type mapping. Apache XalanJ defines the following type mapping between XSLT and Java.

XSLT Type 

Java Type 









Result Tree Fragment 


Extension function support is implemented differently on each XSLT processor which makes it difficult to port XSLT code from one processor to another.

In order to run a transformation that makes use of Java code, you have to ensure that the compiled Java code (.class) is reachable from the CLASSPATH. This is a pesky setting which requires changing the environment variable called CLASSPATH. Fortunately Stylus Studio provides a flexible mechanism to include the Java compiled code (directories or Jar files) at the project level and, if the code is located under the project, Stylus Studio saves the path using a relative form. Therefore, you can move your project to a different location without fear of breaking the link between your XSLT and your Java code.

In the following screenshot, we see how to bind a Java class using XalanJ. The Xalan Java namespace declaration is at line 4, the function invocation is at line 19. Notice that the function name is formed with the prefix java: then the full Java class name the “.” and the function name. The Preview shows the transformation result.

Running the same transformation with Saxon requires a small change. The Java class binding is at line 4; the namespace URI is composed of the prefix “java:” and the full Java class name. The function invocation uses the namespace prefix “date:” and the Java method name. The same result is generated in the Preview window.

One major advantage in testing the code with Saxon in Stylus Studio is the ability to run the transformation in the XSLT debugger and step into the Java code to debug the Java extension, which is unique to Stylus Studio. In the following screenshot we see the execution suspended inside the extension function “printDate”. The Call-stack window shows from which XSLT template we came in and which parameter values were passed. The Variables window shows all variables in scope with their values. This is an unparalleled experience for the developers who usually have to write hundreds of trace messages in a log file in order to debug their code.

A side note: notice the second item from the top, in the Call-stack window. The new Saxon Just in Time XSLT to Java compiler generates Java code on the fly!

Stylus Studio mapping tool also provides full support for Java extension functions. In the following screenshot you see how to register a Java extension class, browsing the project CLASSPATH.

Once a Java extension class is registered, all of its functions are exposed. To add a new java function call, simply click on the Java Functions menu item.

With a few additional links, the mapping is complete. The XSLT visual mapping tool allows XSLT developers to take advantage of Java libraries developed by others without the need to know the underlying technical details.

Java is not the only language that can be employed for designing extension functions. If you are developing on Microsoft .NET framework and make use of XslCompiledTransform XSLT processor, you have access to the entire framework API. The following screenshot shows how to implement the date formatter in C# but we could have used JScript as well. The inline code embedded in the XSLT transformation is compiled into MSIL (Microsoft Intermediate Language) by the Just in Time C# compiler.

Inline extension functions have several logistic benefits: you don’t need to compile a separate module and you don’t need to maintain your logic in a different file.

If you need to debug such a transformation, Stylus Studio comes to the rescue Just switch the processor to XslTransform in the XSLT editor scenario dialog and you will be able to debug your code step by step.

In the following screenshot you see the execution suspended inside XSLT match template “date”. The Call-stack window shows the current stack and the variable window shows all variables in scope with their values and XSLT context which represent the XML node currently processed.

The msxsl:script block allows you to import third party .NET libraries which open the door to virtually infinite possibilities. In the following XSLT code fragment, an extension function called “fromEDI” makes use of XML Converters for .NET to parse an EDI file and to return an instance of XPathNavigator which can be manipulated in the XSLT as an XML node.

<msxsl:script implements-prefix='ut' language='C#'>
    <msxsl:assembly href="c:\Program Files (x86)\XML Converters for .NET\bin\XmlConverters.dll"/>
    <msxsl:using namespace="DDTek.XmlConverter" />
    <msxsl:using namespace="System.IO" />
    public XPathNavigator fromEDI(string ediPath)
        ConverterFactory factory = new ConverterFactory();
        string url = "converter:EDI?" + ediPath;
        XmlReaderSettings settings = new XmlReaderSettings();
        settings.XmlResolver = factory.CreateResolver();
        XmlReader reader = XmlReader.Create(url, settings);
        XPathDocument doc = new XPathDocument(reader);
        return doc.CreateNavigator();

 <xsl:template match="/">
    <xsl:variable name="EDIXML" select="ut:fromEDI($EDI)"/>

We hope you enjoyed reading this article. If you have any questions, do not hesitate to contact us.

You can download the Project Zip file by clicking here.

- Stylus Studio Team

 Technical Support

 Follow us on Twitter

 Connect on Facebook

posted on Thursday, August 16, 2012 3:07:37 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback
# Tuesday, July 24, 2012

IVI Technologies Announces Stylus Studio X14 Release 2 Is Now Available

Latest update includes Visual Schema Designer for Relax NG, Saxon 9.4, XSLT Editor Enhancements and More

Miami, FL - July 24h, 2012 – IVI Technologies, the master distributor of Progress® DataDirect® Stylus Studio®, the award-winning XML Integrated Development Environment (IDE) from Progress Software, today announced the immediate availability of the Stylus Studio X14 Release 2 XML Enterprise Suite. This latest update includes a sophisticated Visual Schema Designer for Relax NG and support for the most recent XML technologies and standards.

The Stylus Studio product is marketed and sold through IVI Technologies. IT professionals can download a free trial of the Stylus Studio X14 XML Enterprise Edition Suite today at: http://www.stylusstudio.com/download.

"Stylus Studio X14 Release 2 provides support for the latest XML trends, including recent developments on XSLT 3.0 and XQuery 3.0 and adds a new two-way editor and visual designer for the Relax NG schema language," said Ivan Pedruzzi, Product Manager. “Thanks to a vast feature set which includes database access, legacy data conversion and transformation capabilities, Stylus Studio remains “The Developers’ Choice” for XML no matter the size or sophistication of your IT department.”

"Relax NG is often a better alternative to traditional schema languages like DTD and XML Schema but its adoption is frequently challenged by the lack of sophisticated support in XML tools. This will be no longer an obstacle, thanks to the Stylus Studio X14 Release 2,” Pedruzzi added.

Features and enhancements available in X14 Release 2 include:

New Visual Schema Designer for Relax NG

  • Synchronized split-pane interface that simultaneously shows both a visual Relax NG Diagram and the underlying code
  • Support for XML Schema built-in Simple Types
  • Support for Facets (Parameters)
  • Support for navigating local and external references in the visual diagram
  • Code folding

XSLT Editor Enhancements:

  • Saxon 9.4 - with Just-In-Time Compiler
  • In memory XSLT to byte code generation
  • Additional Support for XSLT 3.0 Working Draft
  • Added new global option to set the default XSLT version

XML Schema Editor Enhancements:

  • Saxon 9.4 Schema Processor - with Just-In-Time Compiler
  • The Saxon processor can now be used to validate XML Schemas
  • The Java built-in schema processor now can be used to validate XML Schema

New XML Converters For Java 6.2:

  • Updated support for ACORD/AL3 from 2009 to 2012
  • New and Updated URI options
  • EDI Converters fixes and enhancements

Pricing and Availability

Stylus Studio X14 Release 2 is now available for free trial download, and for purchase at the Stylus Studio online shop. Stylus Studio X14 Release 2 XML Enterprise Suite and Stylus Studio X14 Release 2 XML Professional Suite are aggressively priced. Volume discounts and competitive upgrades are also available – please visit the online shop for a complete price list. For more information about enterprise licensing, or for any questions about purchasing Stylus Studio products, contact us, or send an email to: StylusStudio@IVITechnologies.com.

About IVI Technologies

IVI Technologies is a global software reseller and a technology company representing world-class software in the integration market space. The company is the primary go-to-market vehicle for the Progress® DataDirect® Stylus Studio® offering, the industry leading XML IDE. Contact IVI Technologies via email at: stylusstudio@ivitechnologies.com or directly at: (305) 748-4155. DataDirect, Progress and Stylus Studio are trademarks or registered trademarks of Progress Software Corporation and/or its subsidiaries or affiliates in the U.S. and other countries. Java and all Java-based marks are trademarks or service marks of Sun Microsystems, Inc. in the U.S. and other countries. Any other trademarks contained herein are the property of their respective owners.


posted on Tuesday, July 24, 2012 3:47:13 PM (Eastern Daylight Time, UTC-04:00)  #    Comments [0] Trackback