Sunday, November 09, 2008

XProc with XSLT completion in oXygen

[[ Note on 2009-11-12: oXygen 11.0 comes with built-in support for XProc and Calabash, so you shouldn't need this anymore if you have oXygen 11+. ]]

After having played a little bit with XProc, and having written a few simple XProc definitions with oXygen, I was tired to always check the step names spelling and to use copy & paste intensively. So I decided to add support for the XProc document type in oXygen.

Thanks to the XProc WG, who has published a schema as part of the current WD (and has done so in various schema languages,) the first step was quite straigthforward. Download the two RNC modules from the current WD, in appendix "D Pipeline Language Summary" (direct links: xproc.rnc and steps.rnc.) While editing an XProc definition, click the Associate Schema... button (see the screenshot below.) In the dialog box, choose RelaxNG Schema, choose the option Compact syntax and select the xproc.rnc file you have just downloaded. The only configuration to change is in Preferences / XML / XML Parser / RELAX NG, and unselect the option Check ID/IDREF (thanks, George.)

Now, you can validate your XProc definition while editing it, as well as enjoy the completion from oXygen. So far, so good. But while editing XProc definitions, you will often use small inline XSLT stylesheets (at least, I do.) And it would be great to have validation and completion for those stylesheet as well. So you have to combine the XProc schemas with XSLT schemas. And thanks to Norman Walsh, there is an RNC schema that validates both XSLT 1.0 and 2.0. You can download them from his blog (direct links: xslt.rnc, xslt10.rnc and xslt20.rnc.)

So far, you have then the schemas for XSLT, and the schemas for XProc, without XSLT. So you have to plug the former within the later. Unfortunately, the XProc RNC schema use the same pattern for p:inline for all steps (that patterns simply accepts anything.) The simple approach here is to redefine that pattern to accept anything except elements in the XSLT namespace, or to accept the xsl:stylesheet element defined in the XSLT schemas. The drawback is that this redefinition occurs for all steps; but so far, it hasn't been a restriction. The custom RNC file is just:

default namespace p = "http://www.w3.org/ns/xproc"
namespace xsl = "http://www.w3.org/1999/XSL/Transform"

include "xproc.rnc" {
   Inline =
      element inline {
         exclude-inline-prefixes.attr?,
         common.attributes,
         ( xslt | AnyButXSLT )
         # I am not sure which one is better...
         # ( xslt | AnyButStylesheet )
      }
}

xslt = external "xslt.rnc"

AnyButXSLT =
   element (* - xsl:*) {
      (_any.attr | text | Any)*
   }
AnyButStylesheet =
   element (* - (xsl:stylesheet|xsl:transform)) {
      (_any.attr | text | Any)*
   }

Just copy & paste this code to a file, for instance xproc-with-xslt.rnc (take care to adapt the two paths to the other RNC schemas as needed.) Then remove the <?oxygen RNGSchema...?> previously added by oXygen to your XProc definition, and associate now your new RNC grammar. That's all!

Labels: , ,

4 Comments:

Blogger Florent Georges said...

I have just uploaded the relevant files to the following addresses: http://www.fgeorges.org/purl/20090407/xproc-with-xslt.rnc, http://www.fgeorges.org/purl/20090407/xproc.rnc, http://www.fgeorges.org/purl/20090407/steps.rnc, http://www.fgeorges.org/purl/20090407/xslt.rnc, http://www.fgeorges.org/purl/20090407/xslt10.rnc, and http://www.fgeorges.org/purl/20090407/xslt20.rnc.

So now I can use those URIs in my pipeline files to link to the schemas, in order to have them validated by my editor. Of course, I use an XML Catalog on each machine, but even without catalogs, the files point to a valid URIs.

12:18  
Anonymous ThankingYouForThis said...

Wow, this is great. Been researching like crazy and cannot finding anything good on the subject but this.

Trying also to find something similar that would allow for integration to various ajax and tag libraries. Know of anything? For instance, when DIV dojoType attribute is "bla" also use this attribute set...

Thanks again.

01:22  
Blogger DaveP said...

Hi Florent.
Just tried the schema.
Missing version attribute on p:declare-step
validation shows:

xproc-with-xslt.rnc:19:27: error: reference to undefined pattern "Any"
xproc.rnc:49:49: error: reference to undefined pattern "extension.attr"
xproc-with-xslt.rnc:19:8: error: reference to undefined pattern "_any.attr"
xproc-with-xslt.rnc:1:1: error: missing "start" element

regards

13:25  
Blogger Florent Georges said...

Yes, the schema has change since (be cause the draft has evolved). So the schemas maybe need to be slightly adapted.

But as I say at the beginning of this post, if you have the version 11+ of oXygen, you don't need those schemas anymore.

15:57  

Post a Comment

Links to this post:

Create a Link

<< Home