A proof of concept of UBL Invoice form filling


Table of Contents

1. A proof of concept of UBL Invoice form filling - Crane-ublform.xsl
1.1. Installation
1.2. Execution
1.3. Copyright
1.4. Getting started
1.5. Line logic
1.6. Line-oriented button pushing
1.7. Data entry field processing
1.8. Generating results
1.9. XML serialization
2. Index

1. A proof of concept of UBL Invoice form filling - Crane-ublform.xsl

Filename: Crane-ublform.xsl

$Id: Crane-ublform.xsl,v 1.7 2014/03/31 19:56:43 admin Exp $

This stylesheet interacts with a user in a web browser to create an OASIS UBL invoice document.

1.1. Installation

There are two steps to install this package: downloading resources and populating directories on a web server.

1.1.1. Download

The Saxon-CE (Client Edition) package is available from http://saxon.sf.net. When the version 1.1 is unpacked, there are three directories:

  • notices/
  • Saxonce/
  • SaxonceDebug/

1.1.2. Installation

Determine where these demonstration files are going to go on your server, say the directory test/, and add the Saxon-CE directories by unzipping the package while preserving directories.

In a temporary area, unzip Crane's package while preserving directories and then move the files into the target directory.

The resulting set of directories and files should look like:

  • test/readme-Crane-ublform.html
  • test/demo/Crane-ublform.html
  • test/demo/Crane-ublform.xsl
  • test/notices/*
  • test/Saxonce/*
  • test/SaxonceDebug/*

1.2. Execution

Open the file test/demo/Crane-ublform.html in a modern web browser.

Fill out the fields as required. The "+" button adds an invoice line. The "-" button removes an invoice line.

The "Reveal" button creates the UBL instance and reveals it on the page. The same logic would be engaged to do anything else with the string that is created containing the UBL document.

1.3. Copyright


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.

1.4. Getting started

match="/" (xsl:template)

The initial template creates the header portion of the page and the first invoice line of the page.

1.5. Line logic

c:addDeleteLine (xsl:template)

This will add (the default) or delete a line from the screen.

Parameter action as="xsd:string"

The identity of any field on the line to be deleted.

When absent, the default is "add" which adds a line at the end.

match="*" mode="c:renumber" (xsl:template)

An identity template except for massaging line-number attributes.

match="@*" mode="c:renumber" (xsl:template)

Any attribute that matches a line-number attribute gets massaged with the running line number.

Parameter lineNumber tunnel="yes" as="xsd:integer"

The running position amongst the active line numbers.

1.6. Line-oriented button pushing

match="input[@name='ladd']" mode="ixsl:onclick" (xsl:template)

The button that adds a line to the set of lines.

match="input[matches(@name,'l\d+del')]" mode="ixsl:onclick" (xsl:template)

The button that removes a line from the set of lines.

1.7. Data entry field processing

match="input" mode="ixsl:onchange" priority="10" (xsl:template)

All field processing must, at the least, establish the new attribute value from the event's value

match="input[matches(@name,'l\d+.*')]" mode="ixsl:onchange" priority="5" (xsl:template)

When the input field is in a line item, determine which line

match="input[matches(@name,'l\d+quan')]" mode="ixsl:onchange" (xsl:template)

When quantity changes, multiply by price to get amount.

Parameter value tunnel="yes" as="xsd:string"

The given quantity.

Parameter line tunnel="yes" as="xsd:string"

The position of the line.

match="input[matches(@name,'l\d+price')]" mode="ixsl:onchange" (xsl:template)

When price changes, multiply by quantity to get amount.

Parameter value tunnel="yes" as="xsd:string"

The given price.

Parameter line tunnel="yes" as="xsd:string"

The position of the line.

c:setAmount (xsl:template)

Change the amount for the line, then update the totals.

Parameter value as="xsd:double?"

The given amount.

Parameter line tunnel="yes" as="xsd:string"

The position of the line.

1.8. Generating results

match="input[@name='reveal']" mode="ixsl:onclick" (xsl:template)

Respond to a request to reveal the generated UBL instance.

c:makeUBL xml:space="preserve" (xsl:template)

Create a UBL Invoice instance using the attributes and text values.

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

Obtain a value stored in an attribute.

Parameter name as="xsd:string"

Identified by the input field's name.

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

Obtain a value stored in a text element.

Parameter id as="xsd:string"

Identified by the element's identifier.

1.9. XML serialization

This mimics what an XML serializer would do when creating angle brackets from structure.

match="*" mode="c:serialize" (xsl:template)

Handle elements and their attributes.

match="text()" mode="c:serialize" (xsl:template)

Handle text inside of elements.

match="comment()" mode="c:serialize" (xsl:template)

Handle a comment.

match="processing-instruction()" mode="c:serialize" (xsl:template)

Handle a processing instruction.

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

Escape the special characters in an attribute's value.

Parameter string as="xsd:string?"

The value to be escaped.

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

Escape the special characters in a PCDATA's value.

Parameter string as="xsd:string?"

The value to be escaped.

2. Index

A E F M S

A

E

F

M

S