Thursday, March 6, 2008

ITM5.1 Profile in HTML format

Finally, a way to convert the Tmw2kProfile XML dump into HTML source.In the article "Formatted Display XML dump of RM profiles", I provided an interesting solution but seemingly half-baked.

  • - unable to export/save the displayed data as HTML or any other format
  • - must be displayed in a browser that is able to parse/translate XML (i.e. Internet Explorer)

Now there is a complete solution, and what you'll need is :

  1. atleast java v1.4

  2. one of the following XSLT jar files
  3. and an xml Stylesheet

This archive. contains the files neccessary.

Basically, there are only 2 steps to create the HTML
  1. Generate the Tmw2kProfile XMLwdmdumpprf -P Tmw2kProfile_name -x > xml_file

  2. Convert from XML to HTML - there are two ways to do this
    1. Apache jar : java -jar xalan.jar -IN xml_file -XSL xsl_file -OUT html_file
    2. Saxon jar : java -jar saxon8.jar -novw xml_file xsl_file > html_file

You can really go to town if you have a script lke the one below, just feed it a list of Tmw2kProfile names and away she rips, the only down side is that EACH conversion can take around 3 to 7 seconds.

#!/bin/sh

# Author: Jim Sander
# Function: Create HTML files from XML and XSL
#
# Saxon8
# java -jar -novw foo.xml foo.xsl
# or
# Apache (supports java 1.3, 1,4 and 1.5)
# java -jar xalan.jar -IN foo.xml -XSL foo.xsl -OUT foo.out

# ############################################################
# Copyright (c) 2005 Gulf Breeze Software (www.gulfsoft.com)
# Original Version by Jim Sander
# Version: 1.0
# ############################################################
# # # #
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
# ############################################################

# ############################################################
# IMPORTANT!!!
# MODIFY the following variables as neccessary
# ############################################################

# Path to saxon8.jar or xalan.jar file
JAR=/usr/local/bin/xml/saxon8.jar # Saxon: http://saxon.sourceforge.net
#JAR=/tmp/itm2html/xalan.jar # Apache XML: http://xml.apache.org

# Path to Java 1.4 or higher
JAVA14="/usr/java14/bin/java"

# XSLT File : XML Stylesheet
XSLT="/usr/local/bin/xml/itm2html/itm_profile_html.xsl"

# Apache XML format
#CMD="$JAVA14 -jar $JAR -IN %s -XSL %s -OUT %s"

# Saxon8 Format
CMD="$JAVA14 -jar $JAR -novw %s %s > %s "


# ############################################################
# Subroutines/functions
# ############################################################
fileCheck (){
ARG=$1
eval "
if [ ! -f \"\$$ARG\" ]; then
print \"Missing $ARG file: \$$ARG\";
#
print \" Note:
edit the XSLT, JAR JAVA14 and CMD variables inside
this script to point to the valid files \"

return 1
fi
"
}

Usage (){
print $*
print "Requires atleast one input ITM profile"
print "`basename $0` < input_itmxml"
print " stdout is html table formatted display"

}
# ############################################################

fileCheck JAR && fileCheck XSLT && fileCheck JAVA14 || exit 1

#if [ $# -gt 0 ]; then Usage; exit 1; fi
if [ $# -gt 0 ]; then echo "Accepts STDIN only"; exit 1; fi

errcnt=0
succnt=0


while read itmprofile_name; do

IN=$itmprofile_name
OUT="${IN%*.xml}"

TMPFILE=/tmp/wdmdumpprf$$.xml;

wdmdumpprf -P $IN -x > ${TMPFILE}
if [ $? -eq 0 ]; then

RUN_CMD=`printf "$CMD" $TMPFILE $XSLT ${OUT}.html`

printf "EXEC: $RUN_CMD"
eval $RUN_CMD
rc=$?
print "RC=$rc"
if [ $rc -ne 0 ]; then
errcnt=`expr $errcnt + 1`
rm -f $OUT
else
succnt=`expr $succnt + 1`
fi

else
echo "Failed 'wdmdumpprf' command" >&2
errcnt=`expr $errcnt + 1`
fi
done
print "Processed $succnt successfully and $errcnt failed"

rm -f $TMPFILE


No comments: