XSLT 1.0 coding advice

Advice sought:

1) modules

2) avoiding repetition, continuations?

========

1) modules

The new library module
http://www.w3.org/2003/g/xml-attributes
[not yet correctly documented]

is intended to be imported, by other people's code.
(see also previously mailed documentation, that I will add soon).

I have never written such a thing before.
I made the following steps:
a) all templates and top-level variables are named in the namespace of 
the module
    - this includes both the templates that I (conceptually) export
      and the templates that are (conceptually) private

b) local params are given simple names, not in the xa namespace.

Is this sufficient?
Or do I need to do other things?

==========

2) avoiding repetition, continuations?

I usually use XSLT 2.0 where it is easier to define user functions etc.

The most difficult bit of the code is detecting relative URIs.
I decided that I would not do proper URI processing (e.g. resolve 
relative refs, in cascading xml:base decls), but simply barf if there 
were nested relative xml:base declarations.

The logic I required was:

   - if I have an xml:base B, and an ancestor xml:base, then if B is 
relative, temrinate with a message
   - if I have a relative xml:base B1 and no ancestor xml:base but an 
html base B2, and I am respecting xml:base within HTML, then if both B1 
and B2 are relative, barf.

Rather than copy/pasting the is-a-uri-relative code, I wanted one copy 
in one place. The method I used was to define a template:

<xsl:template name="xa:if-relative-then-call-continuation">

and to define templates

<xsl:template name="xa:barf">
   which terminates

and

<xsl:template name="xa:barf-if-relative">

and

<xsl:template name="xa:barf-if-both-relative">

defined in terms of xa:if-relative-then-call-continuation and xa:barf.

Since XSLT doesn't support templates as first class objects, I followed 
Michael Kay's advice, in XSLT 2.0, 3rd Edition, Programmer's Reference, 
p198, combined with xsl:choose, to implement the continuation style of 
programming.

---

Is there a more straight forward way, in XSLT 1.0, of only writing the 
relative URI logic once?

Jeremy












-- 
Hewlett-Packard Limited
registered Office: Cain Road, Bracknell, Berks RG12 1HN
Registered No: 690597 England

Received on Tuesday, 19 June 2007 13:52:41 UTC