tag:blogger.com,1999:blog-238154172024-03-14T04:11:45.110+00:00Thoughts on XSLTAndrew WelchUnknownnoreply@blogger.comBlogger54125tag:blogger.com,1999:blog-23815417.post-60216150406476057922011-01-10T13:56:00.002+00:002011-01-10T14:08:36.791+00:00Kernow 1.7 released<div><br /></div><div><span class="Apple-style-span" style="font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; color: rgb(34, 34, 34); line-height: 18px; ">Kernow 1.7 is now available:<br /><ul style="padding-top: 0px; padding-right: 2.5em; padding-bottom: 0px; padding-left: 2.5em; margin-top: 0.5em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; line-height: 1.4; "><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">integrates LexEv (which now reports internal and parameter entities, along with CDATA sections, comments, numeric and entity refs, and the DOCTYPE)</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">On OSX and linux, it uses the "Nimbus" look and feel, on Windows it still uses native</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">includes the latest Saxon HE 9.3.0.2</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">directory transforms: input directory structure is now recreated in the output directory</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">files are correctly released, rather than held while Kernow is open</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">the caching entity resolver now correctly load all files from the cache dir first</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">updated to the latest Bounce version, which fixes some freezing in the sandboxes</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">includes Xerces 2.10 which partially supports XSD 1.1</li><li style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0.25em; margin-left: 0px; text-indent: 0px; ">fixed several small bugs</li></ul><div>Kernow 1.7 is released as a trial version which allows you to hit the run button 100 times, after which you will need to enter a code to continue. The code can be purchased using the Help -> Purchase menu.</div></span></div>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-50134685968016688392010-07-19T14:45:00.002+00:002010-07-19T14:51:26.031+00:00Kernow 1.7 beta availableKernow 1.7 beta is now available: <br /><ul><li>integrates LexEv (which now reports internal and parameter entities, along with CDATA sections, comments, numeric and entity refs, and the DOCTYPE)</li><li>includes Saxon HE 9.2.1.1</li><li>directory transforms: input directory structure is now recreated in the output directory</li><li>files are correctly released, rather than held while Kernow is open</li><li>the caching entity resolver now correctly load all files from the cache dir first</li><li>updated to the latest Bounce version (enabling "folding" in the sandboxes)</li><li>includes Xerces 2.9.0 which partially supports XSD 1.1</li><li>fixed several small bugs</li></ul>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-23815417.post-76271724380276456562009-11-17T10:10:00.004+00:002009-11-17T10:20:46.914+00:00Mark Logic adds XSLT supportMark Logic currently lacks any support for XSLT... but that's about to change: Norm Walsh has <a href="http://norman.walsh.name/2009/11/12/nymug">announced upcoming support for it</a> in version 5.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-75302738335637648652009-09-14T12:54:00.002+00:002009-09-14T13:06:55.378+00:00XML Schema 1.1 tutorialsRoger Costello has created a couple of good <a href="http://www.xfront.com/xml-schema-1-1/">powerpoint presentations on XSD 1.1</a><br />One tutorial is for developers, the other for managers which contains more general wordy descriptions of the benefits of 1.1Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-30553598107854253242008-08-22T14:56:00.005+00:002012-01-26T15:49:10.705+00:00Some sample templates for use with LexEv<p>If your XML has been parsed using <a href="http://andrewjwelch.com/lexev">LexEv</a>, here are some sample templates for handling the LexEv markup.<br /></p><p>To output an entity reference:<br /></p><br /><pre class="prettyprint lang-xsl"><br /><xsl:template match="lexev:entity"><br /> <xsl:value-of disable-output-escaping="yes" select="concat('&amp;', @name, ';')"/> <br /></xsl:template><br /><br /></pre><br /><br /><p>To process a CDATA section as markup:<br /></p><pre><code><br /><xsl:template match="lexev:cdata"><br /> <xsl:apply-templates/> <br /></xsl:template><br /></code></pre><br /> <br /><p>To output a DOCTYPE from the processing instructions:<br /></p><p>In XSLT 1.0 the doctype-public and doctype-system attributes on <code>xsl:output</code> are static and need to be known at compile time, which means I'm afraid you have to do this:<br /></p><pre><code><br /><xsl:template match="/"><br /><xsl:value-of disable-output-escaping="yes"<br /> select="concat('&lt;!DOCTYPE ', name(/*), '&#xa; PUBLIC &quot;',<br /> processing-instruction('doctype-public'), '&quot; &quot;',<br /> processing-instruction('doctype-system'), '&quot;&gt;')"/><br /><xsl:apply-templates/><br /></xsl:template><br /></code></pre><br /> <br /><p>In XSLT 2.0 you can use <code>xsl:result-document</code> where the doctype-public and doctype-system are AVTs which mean their values can be determined at runtime:<br /></p><pre><code><br /><xsl:template match="/"><br /><xsl:result-document<br /> doctype-public="{processing-instruction('doctype-public')}"<br /> doctype-system="{processing-instruction('doctype-system')}"><br /> <xsl:apply-templates/><br /></xsl:result-document><br /></xsl:template><br /></code></pre>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-29478746387884082372008-08-21T15:34:00.004+00:002008-08-21T16:06:53.374+00:00LexEv XMLReader - converts lexical events into markupIt's often a requirement to preserve entity references through to the output (which are usually lost during parsing) or to process the contents of CDATA sections as markup. The <a href="http://andrewjwelch.com/lexev/"><span style="font-style: italic;">Lex</span>ical <span style="font-style: italic;">Ev</span>ent XMLReader</a> wraps the standard XMLReader to convert lexical events into markup so that they can be processed. Typical uses are:<br /><br /><p></p><ul><li>Converting cdata sections into markup: <p><br /><code><![CDATA[ &lt;p&gt; a para &lt;p&gt; ]]></code></p><p>to:</p><p><code><lexev:cdata> <p> a para </p> </lexev:cdata></code></p> <br /> </li><br /> <li>Preserving entity references:<p><br /><code>hello&mdash;world</code></p><p>is converted to:</p><p><code>hello<lexev:entity name="mdash">—</lexev:entity>world</code></p></li><br /><li>Preserving the doctype declaration:<p><br /><code><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"<br />"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></code></p><p>is converted to processing instructions:</p><p><code><?doctype-public -//W3C//DTD XHTML 1.0 Transitional//EN?><br /><?doctype-system http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd?></code></p></li><br /><li>Marking up comments: <p><br /><code><!-- a comment --></code></p><p>is converted to:</p><p><code><lexev:comment> a comment </lexev:comment><span style="font-family:Georgia,serif;"></span></code></p></li></ul><p><br /></p><p>To use LexEvXMLReader with Saxon:</p><br /><code>java -cp saxon9.jar;<b>LexEvXMLReader.jar</b> net.sf.saxon.Transform <b>-x:com.andrewjwelch.lexev.LexEvXMLReader</b> input.xml<br />stylesheet.xslt</code><br /><br /><p>Make sure <code><b>LexEvXMLReader.jar</b></code> is on the classpath, and then tell Saxon to use it with the -x switch (copy and paste this line <code><b>-x:com.andrewjwelch.lexev.LexEvXMLReader</b><code>)<span style="font-family:Georgia,serif;"><br /></span></code></code></p><p><br /><code><code><span style="font-family:Georgia,serif;"></span></code></code></p><p>To use LexEvXMLReader from Java:</p><code>XMLReader xmlReader = new LexEvXMLReader();</code> <br /><p><br /></p><p>You can control the following features of LexEv:</p><ul><br /><li>enable/disable the marking up of entity references</li><br /><li>enable/disable the marking up of CDATA sections</li><br /><li>set the default namespace for the CDATA section markup</li><br /><li>enable/disable the reporting of the DOCTYPE</li><br /><li>enable/disable the marking up of comments</li><br /></ul><br /><p>You can set these through the API (if you are including LexEv in an application), or from the command line using the following system properties:</p><ul><br /><li><code>com.andrewjwelch.lexev.inline-entities</code></li><br /><li><code>com.andrewjwelch.lexev.cdata</code></li><br /><li><code>com.andrewjwelch.doctype.cdataNamespace</code></li><br /><li><code>com.andrewjwelch.lexev.doctype</code></li><br /><li><code>com.andrewjwelch.lexev.comments</code></li><br /></ul><br /><p>For example to set a system property from the command line you would use: <code>-Dcom.andrewjwelch.lexev.comments=false</code></p><br /><p>For support, suggestions and licensing, email lexev@andrewjwelch.com</p>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-29577187306358441252008-07-18T14:58:00.000+00:002008-07-18T15:21:37.876+00:00Kernow 1.6.1<a href="http://kernowforsaxon.sf.net/">Kernow 1.6.1</a> (beta) is now availble both as a <a href="http://kernowforsaxon.sf.net/">download </a>and via <a href="http://kernowforsaxon.sourceforge.net/jws/Kernow.jnlp">web start</a>.<br /><br />Notable things in this release:<br /><br />- Line numbers on the editor panes in the sandboxes (thanks to a new version of <a href="http://www.edankert.com/bounce/index.html">Bounce</a>). You might not think so, but getting line numbers down the side of the editor pane is really involved. It's like block indenting (pressing tab or shift-tab when a block of text is selected) in that it's very low level and requires a lot of coding. Why it's not an intergral part of the editor pane I don't know... <br /><br />- Improved the syntax-checking-as-you-type and highlighting, and added the ability to disable it.<br /><br />- The output area is now also a JEditorPane using Bounce so it supports tag highlighting. This might slow things down because now it's an HTML document where every addition is inserted at the end of the document, instead of just appending to a JTextArea... if this proves to be A Bad Thing I'll revert it back to a plain old text area with plain text.<br /><br />- You can now select which tabs are visible (in options -> tabs) so if you never use certain tabs (like Batch or Schematron) you can remove them.<br /><br />- If you have Saxon SA you can use XML Schema 1.1 (options -> validation)<br /><br />- Improved the parameters dialog to make it less fiddly to enter params<br /><br />- Slight graphical tweaks and likely other things that I've forgotten...Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-23815417.post-79505515314938399682008-07-17T11:11:00.001+00:002008-07-17T11:36:56.654+00:00The Nimbus Look and Feel<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_ypDtgn03LEU/SH8usKbvi0I/AAAAAAAAACM/ceAeHx4-cwA/s1600-h/kernow-nimbus.png"><img style="float:right; margin:0 0 10px 10px;cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_ypDtgn03LEU/SH8usKbvi0I/AAAAAAAAACM/ceAeHx4-cwA/s400/kernow-nimbus.png" border="0" alt=""id="BLOGGER_PHOTO_ID_5223945429022903106" /></a>This is "Nimbus" - the new look and feel that comes with Java 6 Update 10. This is a cross platform l&f which means it should look the same on all platforms. Kernow currently uses the "platform default" look and feel so it should look like a native app on the platform it's run on, but it's hard to make sure it looks right - often what looks ok on Windows will have obscured buttons on Linux... something I should've fixed but never did.<br /><br />Anyway, what do you think?Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-27604038514531686732008-07-11T15:37:00.001+00:002008-07-11T16:09:00.763+00:00Validating co-constrains in XML Schema 1.1 using xs:alternativeRather than mess around with loads of assertions to check your co-constraints, XML Schema 1.1 introduces the <code>xs:alternative</code> instruction which allows you to change the type used to validate the element based on some condition. Instead of defining one type and then adding assertions to check the variations, just define one type per variation, then assign that type based on the condition. <br /><br />To do this you first have to define a default type, then define types for each variation by restricting that type. To choose between them, use <code>xs:alternative</code> as a child of <code>xs:element</code>. Here's an example of a co-constraint - <code>this</code> and <code>that</code> are allowed based on the value of the <code>type</code> attribute of <code>node</code> - and how to validate it:<br /><code><pre><root><br /> <node type="A"><br /> <this/> <br /> </node><br /> <node type="B"><br /> <that/> <br /> </node><br /></root><br /></pre></code><br />Here's the schema:<br /><code><pre><xs:schema <br /> xmlns:xs="http://www.w3.org/2001/XMLSchema" <br /> elementFormDefault="qualified"><br /><br /> <xs:element name="root" type="root"/><br /> <b><xs:element name="node" type="node"><br /> <xs:alternative type="node-type-A" test="@type = 'A'"/> <br /> <xs:alternative type="node-type-B" test="@type = 'B'"/> <br /> </xs:element></b><br /> <xs:element name="this"/><br /> <xs:element name="that"/><br /> <br /> <xs:complexType name="root"><br /> <xs:sequence><br /> <xs:element ref="node" maxOccurs="unbounded"/><br /> </xs:sequence><br /> </xs:complexType><br /> <br /> <b><-- Base type --></b><br /> <xs:complexType name="node"><br /> <xs:sequence><br /> <xs:any/> <br /> </xs:sequence><br /> <xs:attribute name="type" type="allowed-node-types"/><br /> </xs:complexType><br /><br /> <xs:simpleType name="allowed-node-types"><br /> <xs:restriction base="xs:string"><br /> <xs:enumeration value="A"/><br /> <xs:enumeration value="B"/><br /> </xs:restriction><br /> </xs:simpleType> <br /> <br /> <b><-- Type A --></b><br /> <xs:complexType name="node-type-A"><br /> <xs:complexContent><br /> <xs:restriction base="node"><br /> <xs:sequence><br /> <xs:element ref="this"/> <br /> </xs:sequence> <br /> </xs:restriction> <br /> </xs:complexContent><br /> </xs:complexType><br /> <br /> <b><-- Type B --></b><br /> <xs:complexType name="node-type-B"><br /> <xs:complexContent><br /> <xs:restriction base="node"><br /> <xs:sequence><br /> <xs:element ref="that"/> <br /> </xs:sequence> <br /> </xs:restriction> <br /> </xs:complexContent><br /> </xs:complexType> <br /></xs:schema><br /></pre></code><br />I really like this... schema 1.1 will be a joy to use.Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-23815417.post-34645469886392121552008-06-16T14:45:00.001+00:002008-06-16T15:10:07.759+00:00XML Schema co-occurrence constraint workaroundHere's a potential workaround for the co-constraint problem in XML Schema.<br /><br />Given some XML:<br /><pre><code><br /><elem type="typeA"><br /> <typeA/><br /></elem><br /><br /><elem type="typeB"><br /> <typeB/><br /></elem><br /></code></pre><br />...the problem is you can't constrain the contents of <code><elem></code> based on the value of the type attribute.<br /><br />You can do it though, if you add an xsi:type attribute to it to explicitly set its type:<br /><pre><code><br /><elem type="typeA" xsi:type="elem_typeA"><br /> <typeA/><br /></elem><br /><br /><elem type="typeB" xsi:type="elem_typeB"><br /> <typeB/><br /></elem><br /></code></pre><br />with suitable type definitions in the schema:<br /><pre><code><br /><xs:complexType name="elem_typeA"><br /> <xs:sequence><br /> <xs:element ref="typeA"/><br /> ...<br /><br /><xs:complexType name="elem_typeB"><br /> <xs:sequence><br /> <xs:element ref="typeB"/><br /> ... <br /></code></pre><br />...and when the XML is validated the relevant definition will be used.<br /><br />This technique is far from ideal as it involves modifying the source, but only in a way which doesn't break it for anyone else. Given the various options for validating co-constraints, this could well be the most straightforward way (at least until 1.1 comes along).Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-2784747602102466902008-04-25T13:48:00.001+00:002008-04-27T09:58:49.321+00:00The Scrabble Reference<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://www.mobipocket.com/en/eBooks/eBookDetails.asp?BookID=78536&Origine=3931"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://2.bp.blogspot.com/_ypDtgn03LEU/SBHo2c9BFEI/AAAAAAAAABs/UmKpDZqVxi8/s320/scrabble-cover_small.gif" alt="" id="BLOGGER_PHOTO_ID_5193187867517588546" border="0" /></a>The Scrabble Reference is an ebook I've created which allows Scrabble players to easily check if words are legal, to suggest longer words or sub-anagrams given a word and to show what words can be made given some letters (up to 15 letters).<br /><br />There are two versions, <a href="http://www.mobipocket.com/en/eBooks/eBookDetails.asp?BookID=78536&Origine=3931">TWL</a> and <a href="http://www.mobipocket.com/en/eBooks/eBookDetails.asp?BookID=81063&Origine=3931">SOWPODS</a> (TWL is used in the USA, Canada, Thailand and Israel and SOWPODS in the rest of the world)<br /><br />The ebook is in the Mobipocket format which deals with running the ebooks on all devices - PDAs, mobile phones, Blackberries etc so you just need to transform the input to suitable Mobipocket markup, compile the ebook and their client does the rest.<br /><br />I must admit to not being interested in Scrabble, but of course I am interested in XSLT, and given the list of words allowed in Scrabble I thought I should turn them into a product - one that you can run on your phone seems perfect.<br /><br />Generating the ebook was very straightforward - list of strings in, markup out... XSLT 2.0 is ideal for the task.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-89055483502161113892008-04-25T11:18:00.000+00:002008-04-25T11:45:32.892+00:00Relative paths and the document() functionA nice gotcha cropped up today on xsl-list...<br /><br />Relative paths passed to the document() function are resolved against either the XML or the stylesheet depending on what is passed in: a node from the XML will mean the path is resolved against the XML, a string will mean it's resolved against the stylesheet.<br /><br />The gotcha is this - if you modify this:<br /><br /><code>document(@path)</code><br /><br />to this:<br /><br /><code><xsl:variable name="path" select="@path" as="xs:string"/><br />...<br />document($path)<br /></code><br /><br />and <code>@path</code> contains a relative path, then you could get a document not found error, or worse if your XML and XSLT are in the same directory, you won't notice...Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-23815417.post-25886399058974649552008-02-29T16:23:00.001+00:002008-02-29T16:34:31.525+00:00XML Schema - element with text and attributesFor some reason I always forget how to define an element that contains only text but also has attributes. Perhaps it's because it's so verbose, or so non-intuitive for something so simple, who knows. Either way it's something that needs to be committed to memory...<br /><br />So the element:<br /><code><pre><br /><foo bar="bar" baz="baz"/><br /></pre></code><br />is described using:<br /><code><pre><br /><xs:complexType name="foo"><br /> <xs:simpleContent><br /> <xs:extension base="xs:string"><br /> <xs:attribute name="bar" type="xs:string"/><br /> <xs:attribute name="baz" type="xs:string"/><br /> </xs:extension><br /> </xs:simpleContent> <br /></xs:complexType><br /></pre></code><br />nice!Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-23815417.post-22512908027379293802008-02-27T16:10:00.000+00:002008-02-27T16:17:34.931+00:00schema-aware.comI've created a new website <a href="http://schema-aware.com">schema-aware.com</a> which is inteded to contain lots of examples of schema-aware XSLT and XQuery. I've started it off with half a dozen or so and hope to add more as time goes on.<br /><br />I also intend to add a few articles about schema-aware transforms - how the run them from the command line, from Java, the various flags involved, how to write schemas to allow you to use the types in your XSLT etc... My intentions are good, we'll have to see how much I actually do.Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-55840533317995102702008-01-31T15:01:00.000+00:002008-01-31T15:20:27.642+00:00Kernow 1.6 betaI've uploaded a new version of Kernow (1.6) which contains the rather nice "XSLT Sandbox" tab. This tab has the XML pane on the left, the XSLT pane on the right and a transform button... and that's it. It's intended for anyone who wants to quickly try something out without the hassle of files, the command line or starting up a proper IDE. It does error checking as you type and highlights any problems.<br /><br />It's available as the usual download from Sourceforge, or through Java Web Start. If you already run the JWS version it should automatically update itself (any problems just re-install it). I've finally figured out the temperamental errors with the JWS version - it turns out the ant jars included with Kernow were already signed by a previous version and so weren't being signed again, but because they were marked as "lazy" in the jnlp the JWS version would start anyway. (You can tell if a jar has been signed by looking for *.SF and *.DSA in the META-INF directory.)<br /><br />The other improvement I'm pleased to have sorted out is that kernow.config (where all of the settings and combobox history are saved) is now stored in a directory called .kernow in your user.home (which is one up from My Documents in XP). Previously it would've been stored on the deskop for the JWS version which is really annoying - sorry about that. As usual it was a 10 minute job, but just took a while to get around to.<br /><br />I've also separated out the SOAP and eXists extension functions into a separate package, so there's no longer the need for the largish eXist.jar, xmldb.jar and log4j.jar jars to be part of the download.<br /><br />I'll release a non-beta version in a few weeks if no bugs are reported, and I've got around to updating all of the documentation.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-55665976085003977512008-01-31T14:52:00.000+00:002008-01-31T14:59:25.322+00:00Parsing XML into Java 5 EnumsOften when parsing XML into pojos I just resort to writing my own SAX based parser. It can be long winded but I think gives you the greatest flexibility and control over how you get from the XML to objects you can process.<br /><br />One example is with Java 5's Enums, which are great. Given the kind of XML fragment where currencies are represented using internal codes:<br /><br /><code><currency refid="001"/> <!-- 001 is Sterling --><br /><currency refid="002"/> <!-- 002 is Euros --><br /><currency refid="003"/> <!-- 003 is United States Dollars --></code><br /><br />You can represent each currency element with an Enum, which contains extra fields for the additional information:<br /><br /><pre><code>public enum Currency {<br /><br /> GBP ("001", "GBP", "Sterling"),<br /> USD ("002", "EUR", "Euros"),<br /> USD ("003", "USD", "United States Dollar"); <br /><br /> private final String refId;<br /> private final String code;<br /> private final String desc;<br /><br /> Currency(String refId, String code, String desc) {<br /> this.refId = refId;<br /> this.code = code;<br /> this.desc = desc;<br /> }<br /><br /> public String refId() {<br /> return refId;<br /> }<br /><br /> public String code() {<br /> return code;<br /> }<br /><br /> public String desc() {<br /> return desc;<br /> }<br /><br /> // Returns the enum based on it's property rather than its name<br /> // (This loop could possibly be replaced with a static map, but be aware<br /> // that static member variables are initialized *after* the enum and therefore<br /> // aren't available to the constructor, so you'd need a static block. <br /> public static Currency getTypeByRefId(String refId) {<br /> for (Currency type : Currency.values()) {<br /> if (type.refId().equals(refId)) {<br /> return type;<br /> }<br /> }<br /><br /> throw new IllegalArgumentException("Don't have enum for: " + refId);<br /> } <br />}<br /></code></pre><br /><br />Notice how each enum calls its own contructor with the 3 parameters - the refId, the code, and the description. <br /><br />You parse the XML into the enum by calling <code>Currency.getTypeByRefId(String refId)</code> passing in the @refid from the XML. The benefit of using the Enum is that you can then do things like:<br /><br /><code>if (currency.equals(Currency.GBP))</code><br /><br />which is nice and clear, while at the same time being able to call <code>currency.refId()</code> and <code>currency.desc()</code> to get to the other values. <br /><br />The drawback is that because static member variables are initialized after the enum, you can't create a HashMap and fill it for a faster lookup later (unless you use a static block). Instead you have to loop through all known values() for the enum given a refId. Although it feels wrong to loop, the worst case is only the size the of enum so I don't think it's too bad.Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-26476321933110765012008-01-22T14:06:00.000+00:002008-01-22T19:21:41.485+00:00Portability of a stylesheet across schema-aware and non-schema-aware processorsI came across this today, which I thought was really cool and worth a post. It basically allows you to code a transform that is only schema-aware if a schema-aware processor is running it, otherwise it's just a standard transform.<br /><br />In this case I want to do input and output validation, so first I sort out the schemas:<br /><br /><xsl:import-schema schema-location="input.xsd" <br />    namespace="http://www.foo.com" <br />    use-when="system-property('xsl:is-schema-aware')='yes'"/><br /> <br /><xsl:import-schema schema-location="output.xsd" <br />    use-when="system-property('xsl:is-schema-aware')='yes'"/> <br /><br />Note the use-when...<br /><br />Next define two root matching templates, one for schema-aware, one for basic:<br /><br /><xsl:template match="/" <br />    use-when="system-property('xsl:is-schema-aware')='yes'" <br />    priority="2"><br />    <br />    <xsl:variable name="input" as="document-node()"><br />        <xsl:document validation="strict"><br />            <xsl:copy-of select="/"/><br />        </xsl:document><br />    </xsl:variable><br />    <br />    <xsl:result-document validation="strict"><br />        <xsl:apply-templates select="$input/the-root-elem"/><br />    </xsl:result-document><br />    <br /></xsl:template><br /><br /><xsl:template match="/"><br />    <xsl:apply-templates select="the-root-elem"/><br /></xsl:template>    <br />    <br /><xsl:template match="the-root-elem"><br />    ...<br /></xsl:template><br /><br />The root matching template for schema-aware processing uses xsl:document to validate the input, and xsl:result-document to validate the output. Validation can also be controlled from outside the transform, but this way forces it on.<br /><br />I think this is great :)Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-23815417.post-28553778567377081412008-01-22T13:47:00.001+00:002009-07-05T08:06:58.303+00:00The identity transform for XSLT 2.0I was looking at the standard identity transform the other day and realised that for nodes other than elements, the call to apply-templates is redundant. <br /><br /><xsl:template match="@*|node()"><br />  <xsl:copy><br />    <xsl:apply-templates select="@*|node()"/><br />  </xsl:copy><br /></xsl:template><br /><br />Also, although it might be intuitive to think that attributes have separate nodes for their name and value, they are in fact a single node that's copied in it's entirety by xsl:copy.<br /><br />I raised this on xsl-list and suggested seperating out the attribute into a template of its own with just xsl:copy for its body:<br /><br /><xsl:template match="node()"><br />  <xsl:copy><br />    <xsl:apply-templates select="@*|node()"/><br />  </xsl:copy><br /></xsl:template><br /><br /><xsl:template match="@*"><br />  <xsl:copy/><br /></xsl:template><br /><br /><br />Mike Kay suggested a more logical version would be:<br /><br /><xsl:template match="element()"><br />  <xsl:copy><br />    <xsl:apply-templates select="@*,node()"/><br />   </xsl:copy><br /></xsl:template><br /><br /><xsl:template match="attribute()|text()|comment()|processing-instruction()"><br />  <xsl:copy/><br /></xsl:template><br /><br />This turned out to be ideal for three reasons:<br /><br />- the comma between @* and node() will mean the selected nodes will be processed in that order, removing the sorting and deduplication that takes place with union |<br />- apply-templates is only called when it will have an effect<br />- it's clearer that attributes are leaf nodes<br /><br />So there it is... the identity transform for XSLT 2.0Unknownnoreply@blogger.com6tag:blogger.com,1999:blog-23815417.post-3451867370161292992007-09-28T13:04:00.000+00:002007-09-28T13:07:52.202+00:00Kernow 1.5.2I've just uploaded the non-beta version of Kernow 1.5.2.<br /><br />This version contains:<br /><br />- French and German translations <br />- XQuery syntax highlighting and checking as-you-type <br />- Improved cancelling of Single File and Standalone tasks <br />- icon and splash screen <br />- An exe to launch it (for windows users) <br />- context menus <br />- comboboxes remember their selected index <br />- individual combobox entries can be removed by deleting the entry <br />- other small fixesUnknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-88833597227284431022007-09-12T12:01:00.000+00:002007-09-12T12:34:31.817+00:00Connecting to Oracle from XSLTToday I generated a report by connecting directly to an Oracle database from XSLT, and thought I'd share the basic stylesheet. I used <a href="http://www.saxonica.com/documentation/sql-extension/intro.html">Saxon's SQL extension</a>, which is available when saxon8-sql.jar is on the classpath. As I was connecting to Oracle, I also needed to put ojdcb14.jar on the classpath.<br /><br />Here's the stylesheet in it's most basic form, formatted for display in this blog.<br /><br />The important things to note here are:<br /><br />- The sql prefix is bound to "<code>/net.sf.saxon.sql.SQLElementFactory</code>"<br />- The driver is "<code>oracle.jdbc.driver.OracleDriver</code>"<br />- The connection string format is "<code>jdbc:oracle:thin:@1.2.3.4:1234:sid</code>" (note the colon between thin and @ - I missed that first time round) where the IP, port and sid are placeholders for the real values<br />- remember that <code>saxon8-sql.jar</code> and <code>ojdbc14.jar</code> needed to be on the classpath<br /><code><pre><br /><xsl:stylesheet version="2.0"<br /> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"<br /> xmlns:xs="http://www.w3.org/2001/XMLSchema"<br /> xmlns:sql="/net.sf.saxon.sql.SQLElementFactory"<br /> exclude-result-prefixes="xs"<br /> extension-element-prefixes="sql"><br /> <br /><xsl:output indent="yes"/><br /><br /><xsl:param name="driver" <br /> select="'oracle.jdbc.driver.OracleDriver'" <br /> as="xs:string"/><br /><br /><xsl:param name="database" <br /> select="'jdbc:oracle:thin:@123.123.123.123:1234:sid'" <br /> as="xs:string"/><br /><br /><xsl:param name="user" select="'un'" as="xs:string"/><br /><xsl:param name="password" select="'pw'" as="xs:string"/><br /><br /><xsl:variable name="connection"<br /> as="java:java.sql.Connection" <br /> xmlns:java="http://saxon.sf.net/java-type"><br /> <br /> <sql:connect driver="{$driver}" database="{$database}" <br /> user="{$user}" password="{$password}"/><br /></xsl:variable><br /> <br /><xsl:template match="/" name="main"><br /> <root><br /> <sql:query connection="$connection" <br /> table="some_table" <br /> column="*"<br /> row-tag="row" <br /> column-tag="col"/><br /> </root><br /></xsl:template><br /><br /></xsl:stylesheet><br /></pre></code><br />The result of this transform outputs XML in the form:<br /><code><pre><br /><root><br /> <row><br /> <col>data1</col><br /> <col>data2</col><br /> <col>data3</col><br /> <col>data4</col><br /> </row><br /> ....<br /></root><br /></pre></code><br />where <code><root></code> is the wrapper element, and <code><row></code> and <code><col></code> are the element names specified in the <code><sql:query></code> element.<br /><br />And that's it - connecting to an Oracle database from within XSLT.Unknownnoreply@blogger.com3tag:blogger.com,1999:blog-23815417.post-1589590171107514352007-09-03T15:59:00.000+00:002007-09-03T16:29:31.326+00:00Kernow 1.5.2 beta b2 availableI've just uploaded a new version of Kernow. This one was pretty much already available via Java Web Start, this makes it available via the normal download route.<br /><br />New features/fixes:<br /><br />- Added syntax highlighting and checking as-you-type to the XQuery Sandbox tab. Syntax highlighting's provided using Bounce's XMLEditorKit - I'm hoping to use Netbeans' nbEditorKit in a future version which will add line numbers, code completion etc. I've put together the checking-as-you-type and error highlighting using Saxon's error reporting. This is really cool, so I'm planning on doing an equivalent "XSLT Sandbox" soon... perhaps using Netbeans RCP. Not sure yet.<br /><br />- Added an icon and splashsceen. These came about because JWS and the exe benefit from them. Are they any good? I'm not really a graphics person...<br /><br />- Kernow.jar is now a proper executable jar, so you can double click it to run Kernow (if you're on a mac for example)<br /><br />- It's all compiled using Java 1.5, again for mac users where 1.6 isn't supported yet.<br /><br />It's available here: <a href="http://sourceforge.net/projects/kernowforsaxon">Kernow</a>Unknownnoreply@blogger.com0tag:blogger.com,1999:blog-23815417.post-79124232562462989792007-08-30T15:16:00.000+00:002007-08-30T15:30:11.533+00:00Kernow now available via Java Web StartI've been playing around with making Kernow available through Java Web Start. This should be the ideal way to run Kernow as it places a shortcut on your desktop (and in your start menu in Windows) and auto-updates whenever a new version is available.<br /><br />Reading around it seems Java Web Start has had mixed reviews. Personally I really like it, perhaps because I'm using Java 1.6 and Netbeans 6 M10 which makes it all pretty straightforward (auto jar-signing is really helpful in M10).<br /><br />Give it a go, let me know what you think: <a href="http://kernowforsaxon.sourceforge.net/jws.html">Kernow - Java Web Start</a>Unknownnoreply@blogger.com1tag:blogger.com,1999:blog-23815417.post-73935006258572333472007-08-17T14:18:00.000+00:002007-08-17T14:29:53.411+00:00Using XQuery and the slash operator to quickly try out XPathsThis is the coolest thing I've seen in a while... <br /><br />In XQuery you can constuct a node just by writing it, eg:<br /><code><br /><node>I'm a node</node><br /></code><br />and then you can use slash operator to apply an XPath to that node:<br /><code><br /><node>I'm a node</node>/data(.)<br /></code><br />returns "I'm a node"<br /><br />The XML doesn't have to be limited to a single node - you can do:<br /><code><br /><root><br />  <node>foo</node><br />  <node>bar</node><br /></root>/node/data(.)<br /></code><br />...to get "foo bar".<br /><br />Or:<br /><code><br /><root><br />  <node>foo</node><br />  <node>bar</node><br /></root>/node[1]<br /></code><br />to get:<br /><code><br /><node>foo</node><br /></code><br /><br />Using this technique in combination with <a href="http://kernowforsaxon.sf.net/">Kernow's XQuery Sandbox</a> makes it straightforward to paste in some XML and start trying out some XPaths.Unknownnoreply@blogger.com4tag:blogger.com,1999:blog-23815417.post-66659798424129836092007-08-16T14:59:00.000+00:002007-08-16T15:44:44.282+00:00When a = b and a != b both return true...In XPath = and != are set operators. That is, they return true if any item on the left hand side returns true when compared with any item on the right hand side. Or in other words:<br /><br /><i>some x in $seqA, y in $seqB satisfies x op y</i><br /><br />...where "op" is = or != (or > or < etc)<br /><br />To demonstrate this take the two sets ('a', 'b') and ('b', 'c'):<br /><br />$seqA = $seqB returns true because both sets contains 'b'<br /><br />$seqA != $seqB returns true because setA contains 'a' which is not equal to 'c' in setB<br /><br />This catches me out a lot, even though I've been caught out before several times. I really have to think hard about what it is exactly that I'm comparing, and still end up getting it wrong.<br /><br />A simple rules to follow is <b>"never use != where both sides are sequences of more than one item"</b>. 99.9% of the time you won't need to, as much as it feels like the right thing to do. <br /><br />Below are some of the most common operations on sequences, put together for a reference.<br /><br />The two sequences are ('a', 'b') and ('b', 'c'), which can be defined in XSLT as:<br /><br /><xsl:variable name="seqA" select="('a', 'b')" as="xs:string+"/><br /><xsl:variable name="seqB" select="('b', 'c')" as="xs:string+"/><br /><br />or in XQuery as:<br /><br />let $seqA := ('a', 'b')<br />let $seqB := ('b', 'c')<br /><br /><br/><br /> <div><i>Select all items in both sequences</i></div><br /> <div>($seqA, $seqB)</div><br /> <div>Result: a b b c</div><br /><br/><br /> <div><i>Select all items in both sequences, eliminating duplicates</i></div><br /> <div>distinct-values(($seqA, $seqB))</div><br /> <div>Result: a b c</div><br /><br/><br /> <div><i>Select all items that occur in $seq1 but not $seq2</i></div><br /> <div>$seqA[not(. = $seqB)]</div><br /> <div>Result: a</div><br /><br/><br /> <div><i>Select all items that occur in both sequences</i></div><br /> <div>$seqA[. = $seqB]</div><br /> <div>Result: b</div><br /><br/><br /> <div><i>Select all items that do not occur in both sequences</i></div><br /> <div>($seqA[not(. = $seqB)],$seqB[not(. = $seqA)])<br /> <br>or<br><br /> ($seqA, $seqB)[not(. = $seqA[. = $seqB])]<br /> <br /> </div><br /> <div>Result: a c</div><br /><br/><br /> <div><i>Determine if both sequences are identical</i></div><br /> <div>deep-equal($seqA, $seqB)</div><br /> <div>Result: false</div><br /><br/><br /> <div><i>Test if all items in the sequence are different</i></div><br /> <div>count(distinct-values($seqA)) eq count($seqA)</div><br /> <div>Result: true</div><br /><br/>Unknownnoreply@blogger.com2tag:blogger.com,1999:blog-23815417.post-29393288240601594742007-08-15T09:24:00.000+00:002007-08-15T10:31:08.553+00:00The Worlds Fastest Sudoku Solution in XSLT 2.0 for the Worlds Hardest Sudoku - Al Escargot<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_ypDtgn03LEU/RsLIJuCKmpI/AAAAAAAAABE/GsS_ZPWtXdE/s1600-h/Al+escargot.jpg"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer;" src="http://1.bp.blogspot.com/_ypDtgn03LEU/RsLIJuCKmpI/AAAAAAAAABE/GsS_ZPWtXdE/s320/Al+escargot.jpg" alt="" id="BLOGGER_PHOTO_ID_5098857797438315154" border="0" /></a><br />I get a lot of traffic to this blog because of my Sudoku solver. Google analytics tells me most of it lands on the <a href="http://ajwelch.blogspot.com/2006/05/sudoku-solver-complete-and-shes-fast_02.html">original version</a> that I wrote, and not the <a href="http://www.andrewjwelch.com/code/xslt/sudoku/sudoku-solver.html">optimised version</a> that's now the worlds fastest XSLT 2.0 solution - an issue which this post should hopefully rectify.<br /><br />The puzzle on the right is apparently the <a href="http://zonkedyak.blogspot.com/2006/11/worlds-hardest-sudoku-puzzle-al.html">worlds hardest Sudoku puzzle</a>. If I run my solver "<a href="http://www.andrewjwelch.com/code/xslt/sudoku/sudoku-solver.html">Sudoku.xslt</a>" using <a href="http://kernowforsaxon.sourceforge.net/">Kernow's performance testing feature</a> I get this result:<br /><br />Ran 5 times<br />Run 1: 328 ms<br />Run 2: 344 ms<br />Run 3: 328 ms<br />Run 4: 391 ms<br />Run 5: 328 ms<br />Ignoring first 2 times<br />Total Time (last 3 runs): 1 second 47 ms<br />Average Time (last 3 runs): 349 ms<br /><br /><br />So on my machine the average execution time is 349ms, which is pretty good considering the original version would take minutes for several puzzles. As far as I know this version will solve all puzzles in under a second on my machine (Core 2 duo E6600, 2gb).<br /><br />How does it do it? This is taken from the <a href="http://www.andrewjwelch.com/code/xslt/sudoku/sudoku-solver.html">web page</a> where it's hosted:<br /><br />It accepts the puzzle as 81 comma separated integers in the range 0 to 9, with zero representing empty. It works by continuously reducing the number of possible values for each cell, and only when the possible values can't be reduced any further it starts backtracking.<br /><br />The first phase attempts to populate as many cells of the board based on the start values. For each empty cell it works out the possible values using the "Naked Single", "Hidden Single" and "Naked Tuples" techniques in that order (read here for more on the techniques). Cells where only one possible value exists are populated and then the second phase begins.<br /><br />The second phase follows this process:<br /><br /> * Find all empty cells and get all the possible values for each cell (using Naked Single and Hidden Single techniques)<br /> * Sort the cells by least possible values first<br /> * Populate the cells with only one possible value<br /> * If more there's more than one value, go through them one by one<br /> * Repeat<br /><br />This is how it solves the Al Esgargot: A slightly modified version of the solution gives this output with the $verbose parameter set to true. As you can see it's found that it can insert a 1 at position 66 using the static analysis of the puzzle (position 66 is middle-right of the bottom-left group). Next it's decided that there are two possible values 4 and 6 at index 12 (middle-right cell of top-left group), so it tries 4 and continues. With that 4 in place it's found that there's only one possible value at index 39, a 3, so it inserts that and continues. It will keep reducing the possible values based on the current state of the board, inserting the only possible values or trying each one when there are many, until either there are no possible values for an empty cell, or the puzzle is solved.<br /><br />(the solution is shown below)<br /><br />Populated single value cell at index 66 with 1<br />Trying 4 out of a possible 4 6 at index 12<br />Only one value 3 for index 39<br />Trying 5 out of a possible 5 7 at index 10<br />Trying 1 out of a possible 1 9 at index 13<br />Only one value 9 for index 15<br />Trying 6 out of a possible 6 7 at index 16<br />Only one value 7 for index 17<br />Trying 2 out of a possible 2 4 at index 7<br />Trying 6 out of a possible 6 8 at index 2<br />Only one value 8 for index 3<br />Only one value 2 for index 48<br />Only one value 6 for index 57<br />Only one value 5 for index 60<br />Only one value 9 for index 63<br />Only one value 5 for index 74<br />Only one value 1 for index 78<br />Only one value 3 for index 69<br />Only one value 5 for index 71<br />Only one value 6 for index 81<br />Only one value 4 for index 36<br />! Cannot go any further !<br />Trying 8 out of a possible 8 at index 2<br />Only one value 6 for index 3<br />Trying 4 out of a possible 4 5 at index 4<br />Only one value 3 for index 9<br />Only one value 3 for index 23<br />Only one value 4 for index 26<br />Only one value 3 for index 53<br />Only one value 5 for index 54<br />Only one value 4 for index 36<br />Only one value 6 for index 44<br />Only one value 8 for index 48<br />Only one value 2 for index 57<br />Only one value 8 for index 73<br />Only one value 9 for index 47<br />Only one value 7 for index 50<br />Only one value 6 for index 60<br />Only one value 9 for index 64<br />! Cannot go any further !<br />Trying 5 out of a possible 5 at index 4<br />Only one value 9 for index 47<br />Only one value 2 for index 67<br />Only one value 7 for index 49<br />Only one value 9 for index 64<br />Only one value 2 for index 80<br />Only one value 1 for index 32<br />Only one value 2 for index 48<br />Only one value 5 for index 50<br />Only one value 8 for index 58<br />Only one value 8 for index 73<br />! Cannot go any further !<br />Trying 4 out of a possible 4 at index 7<br />Only one value 3 for index 9<br />Only one value 4 for index 23<br />Only one value 3 for index 24<br />Only one value 2 for index 26<br />Only one value 3 for index 53<br />Only one value 5 for index 54<br />Only one value 8 for index 4<br />Trying 2 out of a possible 2 6 at index 2<br />Only one value 6 for index 3<br />Trying 7 out of a possible 7 8 at index 19<br />Only one value 8 for index 20<br />Only one value 7 for index 29<br />Only one value 9 for index 40<br />Only one value 7 for index 50<br />Only one value 6 for index 44<br />Only one value 2 for index 49<br />Only one value 2 for index 28<br />Only one value 8 for index 48<br />Only one value 2 for index 57<br />Only one value 5 for index 67<br />Only one value 7 for index 58<br />Only one value 8 for index 61<br />Only one value 3 for index 68<br />Only one value 2 for index 70<br />! Cannot go any further !<br />Trying 8 out of a possible 8 at index 19<br />Only one value 7 for index 20<br />Only one value 8 for index 29<br />Only one value 9 for index 47<br />Only one value 2 for index 48<br />Only one value 8 for index 57<br />Only one value 4 for index 37<br />Only one value 9 for index 40<br />Only one value 7 for index 49<br />! Cannot go any further !<br />Trying 6 out of a possible 6 at index 2<br />Only one value 2 for index 3<br />Only one value 6 for index 57<br />Trying 7 out of a possible 7 8 at index 19<br />Only one value 8 for index 20<br />Trying 2 out of a possible 2 4 at index 28<br />Only one value 7 for index 29<br />Only one value 9 for index 47<br />Only one value 2 for index 49<br />Only one value 9 for index 40<br />Only one value 6 for index 44<br />Only one value 7 for index 50<br />Only one value 9 for index 59<br />! Cannot go any further !<br />Trying 4 out of a possible 4 at index 28<br />Only one value 9 for index 37<br />Only one value 4 for index 44<br />Only one value 6 for index 42<br />Trying 2 out of a possible 2 7 at index 29<br />Only one value 7 for index 47<br />Only one value 2 for index 49<br />Only one value 7 for index 32<br />Only one value 9 for index 50<br />! Cannot go any further !<br />Trying 7 out of a possible 7 at index 29<br />Only one value 1 for index 32<br />Only one value 2 for index 33<br />Only one value 2 for index 47<br />Trying 7 out of a possible 7 9 at index 49<br />Only one value 9 for index 50<br />Only one value 6 for index 77<br />Only one value 1 for index 78<br />Only one value 5 for index 80<br />Only one value 5 for index 56<br />Only one value 8 for index 60<br />Only one value 2 for index 61<br />Only one value 8 for index 70<br />Only one value 6 for index 71<br />Only one value 9 for index 74<br />Only one value 2 for index 64<br />Only one value 4 for index 81<br />Only one value 4 for index 58<br />Only one value 9 for index 67<br />Only one value 8 for index 73<br />Only one value 2 for index 76<br />Done!<br /><br />1, 6, 2,   8, 5, 7,   4, 9, 3, <br />5, 3, 4,   1, 2, 9,   6, 7, 8, <br />7, 8, 9,   6, 4, 3,   5, 2, 1, <br /><br /><br />4, 7, 5,   3, 1, 2,   9, 8, 6, <br />9, 1, 3,   5, 8, 6,   7, 4, 2, <br />6, 2, 8,   7, 9, 4,   1, 3, 5, <br /><br /><br />3, 5, 6,   4, 7, 8,   2, 1, 9, <br />2, 4, 1,   9, 3, 5,   8, 6, 7, <br />8, 9, 7,   2, 6, 1,   3, 5, 4, <br /><br /><br />If you have a solution that can statically detect more cells to fill using different techniques than I have, or has a better strategy than simply backtracking when there's more than one value, then I'd be interested to know it works. <br /><br />I'm pretty sure the XSLT is as good as it can be, but if you think it can be improved in any way then let me know.Unknownnoreply@blogger.com14