Open Document Spreadsheet to Business Document ODS Genericode


Table of Contents

1. Open Document Spreadsheet to Business Document ODS Genericode - Crane-ods2odsgc.xsl
1.1. Emitting genericode XML from spreadsheet content
1.2. Skeleton genericode output file
2. Open Document Spreadsheet to Genericode Subset Transformation - gcExportSubset.xsl
2.1. Emitting genericode XML from spreadsheet content
2.2. Utility
2.3. Input/output templates
3. Common support ODF access by Crane styesheets - odsCommon.xsl
3.1. ODS file access
3.2. Serializing XML to text
3.3. Identity-related processes
3.4. Miscellaneous
3.5. Column letter representation
4. Index

Import/include tree (in order of importance; reverse import order)

Available invocation parameters

1. Open Document Spreadsheet to Business Document ODS Genericode - Crane-ods2odsgc.xsl

Filename: Crane-ods2odsgc.xsl

Include statement:

$Id: Crane-ods2obdgc.xsl,v 1.5 2018/09/21 20:02:31 admin Exp $

This converts an instance of a subset of OASIS ODF 1.1 into an instance of OASIS Genericode 1.0, presuming that the genericode is a set of CCTS information destined for use in creating schemas.

Copyright (C) - Crane Softwrights Ltd.
              - http://www.CraneSoftwrights.com/links/res-dev.htm

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
- The name of the author may not be used to endorse or promote products
  derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Note: for your reference, the above is the "Modified BSD license", this text
      was obtained 2003-07-26 at http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5

THE AUTHOR MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS CODE FOR ANY
PURPOSE.

row-number-column-name as="xsd:string?" select="()" (xsl:param)

Name the column with which to store the row number.

identification-uri as="xsd:string?" select="()" (xsl:param)

Name the file of replacement Identification information.

ods-uri as="xsd:string?" select="()" (xsl:param)

Comma-separated names of ODS files when not supplying input XML.

raw-sheet-long-name as="xsd:string?" select="()" (xsl:param)

Indicate that the output is raw (all columns optional, no keys, no constraints) by indicating the long name of the column to contain the sheet name.

included-sheet-name-regex as="xsd:string?" select="'^.+$'" (xsl:param)

Indicate which worksheet/table names are to be included.

indent as="xsd:string" select="'yes'" (xsl:param)

Establish the indentation of the result.

c:ods-uri(1) as="xsd:string?" (xsl:function)

Determine actual URI to use

Parameter c:ods-uri as="xsd:string?"

The basis on which to calculate a JAR URI

1.1. Emitting genericode XML from spreadsheet content

ods-uri (xsl:template)

Starting with a set of input ZIP files

match="/" priority="1" (xsl:template)

Establish indentation based on parameter.

match="/directory" priority="3" (xsl:template)

The handling of a file of file names.

c:documentElement match="/office:document | /office:document-content" priority="2" (xsl:template)

Only allow instances with expected content.

Parameter c:roots as="document-node()+"

The root of each input genericode file being processed.

match="/*" priority="1" (xsl:template)

Only allow instances with expected content.

c:Identification (xsl:template)

Replace identification information if provided

1.2. Skeleton genericode output file

2. Open Document Spreadsheet to Genericode Subset Transformation - gcExportSubset.xsl

Path: support/gcExportSubset.xsl

Filename: gcExportSubset.xsl

Include statement:

$Id: gcExportSubset.xsl,v 1.17 2018/09/21 20:02:13 admin Exp $

This converts an instance of a subset of OASIS ODF 1.1 into an instance of OASIS Genericode 1.0.

Copyright (C) - Crane Softwrights Ltd.
              - http://www.CraneSoftwrights.com/links/res-dev.htm

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

- Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
- The name of the author may not be used to endorse or promote products
  derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Note: for your reference, the above is the "Modified BSD license", this text
      was obtained 2003-07-26 at http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5

THE AUTHOR MAKES NO REPRESENTATION ABOUT THE SUITABILITY OF THIS CODE FOR ANY
PURPOSE.

worksheetIdentifier as="xsd:string?" select="if( exists( $raw-sheet-long-name ) ) then if( string( $raw-sheet-long-name ) ) then replace($raw-sheet-long-name,'\W+','') else () else 'ModelName'" (xsl:param)

Name the worksheet identifying column reference identifier.

When this value is the empty string, the worksheet column is not emitted.

lengthen-model-name-uri as="xsd:string?" (xsl:param)

Instructions to lengthen the model name

c:lengthen-model-name-file as="document-node()?" select="if( empty($lengthen-model-name-uri) ) then () else if( doc-available( $lengthen-model-name-uri ) ) then for $d in doc( $lengthen-model-name-uri ) return if ( $d/modelNameMassage ) then $d else error((), 'Unexpected document element in lengthen URI') else error((),'Unable to open lengthen-model-name URI')" (xsl:param)

Instructions to lengthen the model name

indent="yes" (xsl:output)

This file is most legible when indented.

2.1. Emitting genericode XML from spreadsheet content

match="/" (xsl:template)

Only allow instances with expected content.

c:emitGenericode (xsl:template)

Handle a genericode element with column info in spreadsheet.

Parameter c:tables as="element(table:table)*"

All of the tables of sheets contributing to output

2.2. Utility

c:lengthen(1) as="xsd:string?" (xsl:function)

Apply, in reverse order, regular expressions on a string.

Parameter c:value as="xsd:string?"

The value to be massaged.

c:lengthen(2) as="xsd:string?" (xsl:function)

Apply, in reverse order, regular expressions on a string.

Parameter c:value as="xsd:string?"

The value to be massaged.

Parameter c:pass as="element(pass)?"

A pass of the conversion

2.3. Input/output templates

odsTemplate as="document-node()" (xsl:variable)

From the command-line, this is an overriding template file. Without using the command line the template file referenced by the entity is used. In the assembled stylesheet this becomes inline.

3. Common support ODF access by Crane styesheets - odsCommon.xsl

Path: support/odsCommon.xsl

Filename: odsCommon.xsl

$Id: odsCommon.xsl,v 1.18 2014/12/27 22:11:50 admin Exp $

This is a collection of facilities for accessing OpenOffice document files from XSLT stylesheets. There is no knowledge of the target non-ODF vocabularies in this module.

3.1. ODS file access

o:odsTables(1) as="element(table:table)*" (xsl:function)

All of the tables in the ODS document

Parameter o:odsRoot as="element()"

The root of the ODS tree

o:styles match="style:style" use="@style:name" (xsl:key)

A look-up of style names for all styles styles

o:craneStyle(1) as="xsd:string" (xsl:function)

Walk up the style tree finding the closest hieararchical Crane style the given style is considered. Returns closest Crane name as a string.

Parameter o:style as="attribute()*"

The style used in the stylesheet.

o:labeledCells match="table:table-cell[ o:craneStyle(preceding-sibling::table:table-cell[2]/@table:style-name)]" use="substring-after( o:craneStyle(preceding-sibling::table:table-cell[2]/@table:style-name), 'CraneLabel')" (xsl:key)

A table of all "labeled" table cells in the ODS instance

It is assumed that there is exactly one table:table-cell between the cell with the label and the cell with the information.

Intuitively you would think we could just label the actual cell itself, but most of the cells we need have some conditional formatting applied to the cell to decorate the background. Conditional formatting is ignored when there is a style directly applied to the cell.

o:labeledCellsDebug match="table:table-cell[ o:craneStyle(preceding-sibling::table:table-cell[2]/@table:style-name)]" use="1" (xsl:key)

A copy of the "labeled" cells, but with a fixed lookup value for diagnostic purposes.

o:craneStyledCells match="table:table-cell[o:craneStyle(@table:style-name)]" use="o:craneStyle(@table:style-name)" (xsl:key)

A table of all "Crane styled" table cells in the ODS instance

o:labeledCell(2) as="node()?" (xsl:function)

Obtain given Crane labeled cell below given point in table.

Parameter o:labelSuffix as="xsd:string"

The suffix to "CraneLabel" of the cell being obtained

Parameter o:tableTopNode as="node()"

The point under which the item is found

o:odsCell2Text(1) as="xsd:string?" (xsl:function)

Get the text value of the table cell current node.

Parameter o:cell as="element(table:table-cell)?"

Which cell is needed?

o:text2odsCellContent (xsl:template)

Set the text value of the table cell current node.

3.2. Serializing XML to text

o:XML2odsCell (xsl:template)

For any given ODS table cell, if there is a genericode item for the cell, the replace it preserving XML syntax ... otherwise preserve the cell.

Parameter o:item as="document-node()" required="yes"

Item whose value replaces that which is in the cell

Parameter o:noAttributes tunnel="yes" as="xsd:boolean"

Skip the preservation of attributes in the copied item

Parameter o:noPreserve tunnel="yes" as="xsd:boolean"

Skip the preservation of the value if no value supplied.

match="*" mode="o:XML2odsCell" (xsl:template)

Set the XML text file of the table cell current node.

Note that it is impossible to know what literal delimeters are being used for attributes, so this code assumes double quotes are being used.

Parameter o:ignoredNamespaceURIs tunnel="yes" as="xsd:string*"

Which namespace URI strings are covered off by other declarations?

match="text()" mode="o:XML2odsCell" (xsl:template)

Set the XML text file of the table cell current node.

match="comment()" mode="o:XML2odsCell" (xsl:template)

Set the XML text file of the table cell current node.

match="processing-instruction()" mode="o:XML2odsCell" (xsl:template)

Set the XML text file of the table cell current node.

3.3. Identity-related processes

match="@*|node()" mode="#default o:skipCurrentMatch" (xsl:template)

The identity template is used to copy all nodes not already being handled by other template rules.

Note there are two modes here: the default mode handles most of the nodes in the entire document; the o:skipCurrentMatch mode will copy the current node only and then switches to the default mode. This allows a matched node not to be re-matched but just simply copied.

3.4. Miscellaneous

o:sort(1) as="xsd:anyAtomicType*" (xsl:function)

Sort the supplied set of atomic items.

Parameter o:items as="xsd:anyAtomicType*"

The items to be sorted

o:sortNodes(1) as="node()*" (xsl:function)

Sort the supplied set of nodes.

Parameter o:nodes as="node()*"

The nodes to be sorted

o:column(1) as="xsd:double+" (xsl:function)

Return the sequence of 1-origin column numbers corresponding to the given table-cell or table-column.

This will return a runtime error if the node passed is neither a table-cell nor a table-column.

Parameter o:cell as="node()"

The table cell being counted within it's row.

o:row(1) as="xsd:double+" (xsl:function)

Return the sequence of 1-origin row numbers corresponding to the given table-row.

Parameter o:row as="element(table:table-row)"

The table row being counted within it's table.

o:text2odsCell match="table:table-cell" mode="o:text2odsCell" (xsl:template)

For the current ODS table cell, if there is a non-empty text item for the cell, then replace it with a simple text value ... otherwise preserve it.

Parameter o:item as="node()?" required="yes"

Item whose value replaces that which is in the cell

Parameter o:noAttributes tunnel="yes" as="xsd:boolean"

Skip the preservation of attributes in the copied item

Parameter o:noPreserve tunnel="yes" as="xsd:boolean"

Skip the preservation of the value if no value supplied.

3.5. Column letter representation

This algorithm was sketched out in Python and then translated to XSLT.

from string import atoi, find
from sys import exit

letters="_ABCDEFGHIJKLMNOPQRSTUVWXYZ"

def alpha2num( alpha ):
    alpha = "___"+alpha
    alpha = alpha[-3:]
    return find( letters, alpha[0:1] ) * 26*26 +\
           find( letters, alpha[1:2] ) * 26 +\
           find( letters, alpha[2:3] )

def num2alpha( num ):
    first = int( ( num - 1 ) / ( 27*26 ) )
    result = letters[ first ]
    result += letters[ int( ( ( num - 1 + ( first * 26 )) % ( 27 * 26 ) ) / 26 ) ]
    result += letters[ ( num - 1 ) % 26 + 1 ]
    return result

for each in range (1, 1025):
    alpha = num2alpha( each )
    this = alpha2num( alpha )
    print "%d=%s=%d" % (each,alpha,this ),
    if each != this:
       print "Problem!"
       exit(1)

for each in range (1, 1025):
    alpha = num2alpha ( each )
    if "_" in alpha: print alpha,

o:columnAlpha2Numeric(1) as="xsd:integer" (xsl:function)

Translate a column alpha to a column number.

Parameter o:alpha as="xsd:string"

Up to three characters of a column alpha indicator.

o:alpha2ordinal(1) as="xsd:integer" (xsl:function)

Translate a column letter to an ordinal number.

Parameter o:alpha as="xsd:string"

Nothing or a single letter.

o:columnNumeric2Alpha(1) as="xsd:string" (xsl:function)

Translate a column number to a column alpha.

Parameter o:numeric as="xsd:integer"

An integer to be converted into a column number.

o:ordinal2alpha(1) as="xsd:string" (xsl:function)

Translate an ordinal number to a column letter

Parameter o:ordinal as="xsd:integer"

The digit between 0 and 26, where zero is suppressed

o:testAlpha2Numeric (xsl:template)

Regression test for alpha to numeric

o:translateFormula(3) as="text()*" (xsl:function)

Translate any row/column position by augmenting row and column numbers

Parameter o:formula as="xsd:anyAtomicType?"

The formula text to be translated.

Parameter o:columnOffset as="xsd:integer"

The offset amount to be added to the column.

Parameter o:rowOffset as="xsd:integer"

The offset amount to be added to the row.

o:address(1) as="xsd:string" (xsl:function)

Return the fully-qualified address of the current table cell.

Parameter o:cell as="element(table:table-cell)"

The table cell being asked about.

4. Index

A C D E I L O R S T W X

A

C

D

E

I

L

O

R

S

T

W

X