<?xml version="1.0" encoding="utf-8"?>
<feed xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom">
  <title>Nesterovsky bros</title>
  <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/" />
  <link rel="self" href="http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetAtom" />
  <icon>favicon.ico</icon>
  <updated>2008-09-05T14:27:45.658915-07:00</updated>
  <author>
    <name>Nesterovsky bros</name>
  </author>
  <subtitle />
  <id>http://www.nesterovsky-bros.com/weblog/</id>
  <generator uri="http://dasblog.info/" version="2.1.8102.813">DasBlog</generator>
  <entry>
    <title>What you can do with jxom</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0141ac17-edb2-4d0e-9781-fb76568a7d70.aspx</id>
    <published>2008-09-05T08:39:50.607-07:00</published>
    <updated>2008-09-05T14:27:45.658915-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We're facing a task of conversion of a java method into a state machine. This
is like to convert a SAX Parser, pushing data, into an Xml Reader, which pulls data. 
</p>
        <p>
The task is formalized as:
</p>
        <ul>
          <li>
for a given method containing split markers create a class perimitting iteration;</li>
          <li>
each iteration performs part of a logic of a method. 
</li>
        </ul>
        <p>
We have defined rules converting all statements into a state machine except of the
statement <b><code>synchronied</code></b>. In fact the logic it rather linear, however
the most untrivial conversion is for <b><code>try</code></b> statement. Consider
an example:
</p>
        <p style="padding-left: 1em">
          <code>
            <b>public</b>
            <b>class</b> Test<br />
{<br /><b>void</b> method()<br /><b>throws</b> Exception<br />
{<br /><b>try</b><br />
{<br />
A();<br />
B();<br />
}<br /><b>catch</b>(Exception e)<br />
{<br />
C(e);<br />
}<br /><b>finally</b><br />
{<br />
D();<br />
}<br /><br />
E();<br />
}<br /><br /><b>private</b> void A()<br /><b>throws</b> Exception<br />
{<br />
// logic A<br />
}<br /><br /><b>private</b> void B()<br /><b>throws</b> Exception<br />
{<br />
// logic B<br />
}<br /><br /><b>private</b><b>void</b> C(Exception e)<br /><b>throws</b> Exception<br />
{<br />
// logic C<br />
}<br /><br /><b>private</b><b>void</b> D()<br /><b>throws</b> Exception<br />
{<br />
// logic D<br />
}<br /><br /><b>private</b><b>void</b> E()<br /><b>throws</b> Exception<br />
{<br />
// logic E<br />
}<br />
}</code>
        </p>
        <p>
Suppose we want to see <code>method()</code> as a state machine in a way that split
markers are after calls to methods <code>A()</code>, <code>B()</code>, <code>C()</code>, <code>D()</code>, <code>E()</code>.
This is how it looks as a state machine:
</p>
        <p style="padding-left: 1em;">
          <code>Callable&lt;Boolean&gt; methodAsStateMachine()<br /><b>throws</b> Exception<br />
{<br /><b>return</b><b>new</b> Callable&lt;Boolean&gt;()<br />
{<br /><b>public</b> Boolean call()<br /><b>throws</b> Exception<br />
{<br /><b>do</b><br />
{<br /><b>try</b><br />
{<br /><b>switch</b>(state)<br />
{<br /><b>case</b> 0:<br />
{<br />
A();<br />
state = 1;<br /><br /><b>return</b><b>true</b>;<br />
}<br /><b>case</b> 1:<br />
{<br />
B();<br />
state = 3;<br /><br /><b>return</b><b>true</b>;<br />
}<br /><b>case</b> 2:<br />
{<br />
C(ex);<br />
state = 3;<br /><br /><b>return</b><b>true</b>;<br />
}<br /><b>case</b> 3:<br />
{<br />
D();<br /><br /><b>if</b> (currentException != <b>null</b>)<br />
{<br /><b>throw</b> currentException;<br />
}<br /><br />
state = 4;<br /><br /><b>return</b><b>true</b>;<br />
}<br /><b>case</b> 4:<br />
{<br />
E();<br />
state = -1;<br /><br /><b>return</b><b>false</b>;<br />
}<br />
}<br /><br /><b>if</b> (currentException == <b>null</b>)<br />
{<br />
currentException = <b>new</b> IllegalStateException();<br />
}<br />
}<br /><b>catch</b>(Throwable e)<br />
{<br />
currentException = <b>null</b>;<br /><br /><b>switch</b>(state)<br />
{<br /><b>case</b> 0:<br /><b>case</b> 1:<br />
{<br /><b>if</b> (e <b>instanceof</b> Exception)<br />
{<br />
ex = (Exception)e;<br />
state = 2;<br />
}<br /><b>else</b><br />
{<br />
currentException = e;<br />
state = 3;<br />
}<br /><br /><b>continue</b>;<br />
}<br /><b>case</b> 2:<br />
{<br />
currentException = e;<br />
state = 3;<br /><br /><b>continue</b>;<br />
}<br />
}<br /><br />
currentException = e;<br />
state = -1;<br />
}<br />
}<br /><b>while</b>(false);<br /><br /><b>return</b><b>this</b>.&lt;Exception&gt;error();<br />
}<br /><br />
@SuppressWarnings("unchecked")<br /><b>private</b> &lt;T <b>extends</b> Throwable&gt; <b>boolean</b> error()<br /><b>throws</b> T<br />
{<br /><b>throw</b> (T)currentException;<br />
}<br /><br /><b>private</b><b>int</b> state = 0;<br /><b>private</b> Throwable currentException = <b>null</b>;<br /><b>private</b> Exception ex = <b>null</b>;<br />
};<br />
}</code>
        </p>
        <p>
Believe it, or not but this transformation can be done purely in xslt 2.0 with the
help of the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0141ac17-edb2-4d0e-9781-fb76568a7d70&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f16%2fXsltForTheJxomJavaXmlObjectModel.aspx">jxom
(Java xml object model)</a>. We shall update <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=0141ac17-edb2-4d0e-9781-fb76568a7d70&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">jxom.zip</a> whenever
this module will be implemented and tested.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0141ac17-edb2-4d0e-9781-fb76568a7d70" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Xslt 2.0 casuistry</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/09/03/Xslt20Casuistry.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,afe516f6-a2f9-4b8c-9445-b1bdb1e5daab.aspx</id>
    <published>2008-09-03T05:34:06.608-07:00</published>
    <updated>2008-09-03T05:44:47.0382614-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the xslt one can express logically the same things in different words like:
</p>
        <p>
        </p>
        <p>
          <code>  exists($x)</code>
          <br />
and<br /><code>  every $y in $x satisfies exists($y)</code></p>
        <p>
          <b>newbie&gt;</b> Really the same?<br /><b>expert&gt;</b> Ops... You're right, these are different things! 
</p>
        <p>
What's the difference?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=afe516f6-a2f9-4b8c-9445-b1bdb1e5daab" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Tuples and maps - next try</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/08/30/TuplesAndMapsNextTry.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,3a3777a4-2e05-403c-b87a-dacaa6124f40.aspx</id>
    <published>2008-08-30T00:44:44.061-07:00</published>
    <updated>2008-08-30T03:16:41.5545526-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was already writing about tuples and maps in the xslt (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3a3777a4-2e05-403c-b87a-dacaa6124f40&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f07%2f10%2fTuplesAndMapsStatusCLOSEDWONTFIX.aspx"> Tuples
and maps - Status: CLOSED, WONTFIX</a>, and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3a3777a4-2e05-403c-b87a-dacaa6124f40&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f05%2f18%2fTuplesAndMapsInSaxon.aspx"> Tuples
and maps in Saxon</a>).
</p>
        <p>
Now, I want to argue on a use case, and on how xslt processor can detect such a use
case and implement it as map. This way, for a certain conditions, a sequences could
be treated as maps (or as sets).
</p>
        <p>
Use case.
</p>
        <p>
There are two stages:
</p>
        <ul>
          <li>
a logic collecting nodes/values satisfying some criteria.</li>
          <li>
process data, and take a special action whenever a node/value is collected on the
previous stage.</li>
        </ul>
        <p>
Whenever we're talking of nodes than result of the first stage is a sequence <code>$set
as node()*</code>. The role of this sequence is a set of nodes (order is not important).
</p>
        <p>
The second stage is usually an <code>xsl:for-each</code>, an <code>xsl:apply-templates</code>,
or something of this kind, which repeatedly verifies whether a some <code>$node as
node()?</code> belongs to the <code>$set</code>, like a following: <code>$node intersect
$set</code>, or <code>$node except $set</code>.
</p>
        <p>
In spite of that we're still using regular xpath 2.0, we have managed to express
a set based operation. It's a matter of xslt processor's optimizer to detect
such a use case and consider a sequence as a set. In fact the detection rule is rather
simple. 
</p>
        <div style="padding-left: 1em">
          <div>
For expressions <code>$node except $set</code> and <code>$node intersect $set</code>:
</div>
          <ul>
            <li>
              <code>$set</code> can be considered as a set, as order of elements is not important;</li>
            <li>
chances are good that a <code>$set</code> being implemented as a set outperforms implementation
using a list or an array.</li>
          </ul>
        </div>
        <p>
Thus what to do? Well, I do not think I'm the smartest child, quite opposite...
however it worth to hint this idea to xslt implementers (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=3a3777a4-2e05-403c-b87a-dacaa6124f40&amp;url=http%3a%2f%2fsourceforge.net%2fforum%2fforum.php%3fthread_id%3d2183484%26forum_id%3d94026"> Suggest
optimization</a>). I still do not know if it was fruitful...
</p>
        <p>
P.S. A very similar use case exists for a function index-of($collection, $item). 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=3a3777a4-2e05-403c-b87a-dacaa6124f40" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Expression parser in the xslt.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/08/12/ExpressionParserInTheXslt.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2d6b3a53-aa1b-421f-b0c9-26e7ac535ffd.aspx</id>
    <published>2008-08-12T07:45:54.469-07:00</published>
    <updated>2008-08-12T13:06:04.9189281-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I know we're not the first who create a parser in xslt. However I still want to share
our implementation, as I think it's beautiful. 
</p>
        <p>
In our project, which is conversion from a some legacy language to java, we're
dealing with dynamic expressions. For example in the legacy language one can filter
a collection using an expression defined by a string: <code>collection.filter("a
&gt; 0 and b = 7");</code></p>
        <p>
Whenever expression string is calculated there is nothing to do except to parse such
string at runtime and perform filtering dynamically. On the other hand we have found
that in the majority of cases literal strings are used. Thus we have decided to optimize
this route like this:
</p>
        <p style="padding-left: 1em;">
          <code>  collection.filter(<br />
    new Filter&lt;T&gt;()<br />
    {<br />
      boolean filter(T value)<br />
      {<br />
        return (value.getA() &gt; 0) and (value.getB()
= 7);<br />
      }<br />
    });</code>
        </p>
        <p>
This means that we're converting that expression string into java code on the
generation stage.
</p>
        <p>
In the xslt - our generator engine - this means that we have to convert a string into
expression tree like this:
</p>
        <p style="padding-left: 1em;">
          <code>(a &gt; 7 or a= 3) and c * d = 2.2</code>
        </p>
        <p>
to
</p>
        <p style="padding-left: 1em;">
          <code> &lt;and&gt;<br />
  &lt;or&gt;<br />
    &lt;gt&gt;<br />
      &lt;identifier&gt;a&lt;/identifier&gt;<br />
      &lt;integer&gt;7&lt;/integer&gt;<br />
    &lt;/gt&gt;<br />
    &lt;eq&gt;<br />
      &lt;identifier&gt;a&lt;/identifier&gt;<br />
      &lt;integer&gt;3&lt;/integer&gt;<br />
    &lt;/eq&gt;<br />
  &lt;/or&gt;<br />
  &lt;eq&gt;<br />
    &lt;mul&gt;<br />
      &lt;identifier&gt;c&lt;/identifier&gt;<br />
      &lt;identifier&gt;d&lt;/identifier&gt;<br />
    &lt;/mul&gt;<br />
    &lt;decimal&gt;2.2&lt;/decimal&gt;<br />
  &lt;/eq&gt;<br />
&lt;/and&gt;</code>
        </p>
        <p style="padding-left: 1em">
Our parser fits naturally to the world of parsers: it uses <code>xsl:analyze-string</code> instruction
to tokenize input and parses tokens according to an expression grammar. During implementation
I've found some new to me things. I think they worth mentioning:
</p>
        <ul>
          <li>
            <div>
As tokenizer is defined as a big regular expression, we have rather verbose <code>regex</code> attribute
over <code>xsl:analyze-string</code>. It was hard to edit such a big line until I've
found there is <code>flag="x"</code> option that solves formatting problems:<br /><p style="padding-left: 1em; font-style: italic">
The flags attribute may be used to control the interpretation of the regular expression...
If it contains the letter x, then whitespace within the regular expression is ignored.
</p>
This means that I can use spaces to format regular expression and <code>/s</code> to
specify space as part of expression. 
</div>
          </li>
          <li>
Saxon 9.1.0.1 has inefficiency in implementation of <code>xsl:analyze-string</code> instruction,
whenever regex contains literal value however with '{' character (e.g. "\p{{L}}"),
as it considers the value to be an AVT and delays pattern compilation until runtime,
which it does every time instruction is executed.</li>
        </ul>
        <p>
Use following link to see the xslt: <a target="_blank" href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2d6b3a53-aa1b-421f-b0c9-26e7ac535ffd&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fxslt%2fexpression-parser.xslt">expression-parser.xslt</a>.<br />
To see how to generate java from an xml follow this link: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2d6b3a53-aa1b-421f-b0c9-26e7ac535ffd&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f16%2fXsltForTheJxomJavaXmlObjectModel.aspx"> Xslt
for the jxom (Java xml object model)</a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2d6b3a53-aa1b-421f-b0c9-26e7ac535ffd&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">jxom.zip</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2d6b3a53-aa1b-421f-b0c9-26e7ac535ffd" />
      </div>
    </content>
  </entry>
  <entry>
    <title>SFINAE in xslt? - or native exception handling.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/07/31/SFINAEInXsltOrNativeExceptionHandling.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b7f6d884-fe84-4382-815f-15e02faff179.aspx</id>
    <published>2008-07-31T04:52:21.158-07:00</published>
    <updated>2008-08-01T23:08:08.6220097-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yesterday, incidentally, I've arrived to a problem of a dynamic error during evaluation
of a template's match. This reminded me <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fSubstitution_failure_is_not_an_error" rel="nofollow" target="_blank"> SFINAE</a> in
C++. There the principle is applied at compile time to find a matching template.
</p>
        <p>
I think people underestimate the meaning of this behaviour. The effect of dynamic
errors occurring during pattern evaluation is described in the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23pattern-errors" rel="nofollow" target="_blank">specification</a>:
</p>
        <p style="padding-left: 1em; font-style: italic">
Any dynamic error or type error that occurs during the evaluation of a pattern against
a particular node is treated as a recoverable error even if the error would not be
recoverable under other circumstances. The optional recovery action is to treat the
pattern as not matching that node.
</p>
        <p>
This has far reaching consequences, like an error recovery. To illustrate what I'm
talking about please look at this simple stylesheet that recovers from "Division by
zero.":
</p>
        <p style="padding-left: 1em; font-family: monospace">
&lt;xsl:stylesheet version="2.0"<br />
  xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;<br /><br />
&lt;xsl:template match="/"&gt;<br />
  &lt;xsl:variable name="operator" as="element()+"&gt;<br />
    &lt;div divident="10" divisor="0"/&gt;<br />
    &lt;div divident="10" divisor="2"/&gt;<br />
  &lt;/xsl:variable&gt;<br /><br />
  &lt;xsl:apply-templates select="$operator"/&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;xsl:param name="NaN" as="xs:double" select="1.0 div 0"/&gt;<br /><br />
&lt;xsl:template<br />
  match="div[(xs:integer(@divident) div xs:integer(@divisor)) ne $NaN]"&gt;<br />
  &lt;xsl:message select="xs:integer(@divident) div xs:integer(@divisor)"/&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;xsl:template match="div"&gt;<br />
  &lt;xsl:message select="'Division by zero.'"/&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt; 
</p>
        <p>
Here, if there is a division by zero a template is not matched and other template
is selected, thus second template serves as an error handler for the first one. Definitely,
one may define much more complex construction to be handled this way.
</p>
        <p>
I never was a purist (meaning doing everything in xslt), however this example along
with <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f18%2fIndirectFunctionCallInXslt20.aspx"> indirect
function call</a>, shows that xslt is rather equiped language. One just need to be
smart enough to understand how to do a things.
</p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f06%2f26%2fTrycatchBlockInXslt20ForSaxon9.aspx">Try/catch
block in xslt 2.0 for Saxon 9</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=b7f6d884-fe84-4382-815f-15e02faff179" />
      </div>
    </content>
  </entry>
  <entry>
    <title>On the job applicants...</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/07/28/OnTheJobApplicants.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5dfdbafd-389e-4004-93fe-d50858c7009e.aspx</id>
    <published>2008-07-28T03:54:54.09-07:00</published>
    <updated>2008-08-01T11:48:17.8793469-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Among other job activities, we're from time to time asked to check technical skills
of job applicants.
</p>
        <p>
Several times we were interviewing people who're far below the acceptable professional
skills. It's a torment for both sides, I should say.
</p>
        <p>
To ease things we have designed a small questionnaire (specific to our projects) for
job applicants. It's sent to an applicant before the meeting. Even partially answered,
this questionnaire constitutes a good filter against profanes: 
</p>
        <p style="padding-left: 1em; font-family: monospace">
&lt;questionnaire&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in XML Schema (xsd)
as lacking, bad, good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in xslt 2.0/xquery 1.0
as lacking, bad, good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in xslt 1.0 as lacking,
bad, good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in java as lacking,
bad, good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in c# as lacking, bad,
good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please estimate your knowledge in sql as lacking, bad,
good, or perfect.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      For logical values A, B, please rewrite logical expression
"A and B" using operator "or".<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      For logical values A, B, please rewrite logical expression
"A = B" using operators "and" and "or".<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      There are eight balls, with only one heavier than some
other.<br />
      What is a minimum number of weighings reveals the heavier
ball?<br />
      Please be suspicious about the "trivial"
solution.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      If A results in B. What one may say about the reason
of B?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      If only A or B result in C. What one may say about
the reason of C?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please define an xml schema for this questionnaire.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Please create a simple stylesheet creating an html
table based on this questionnaire.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      For a table A with columns B, C, and D, please create
an sql query selecting B groupped by C and ordered by D.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      For a sequence of xml elements A with attribute B,
please write a stylesheet excerpt creating a sequence of elements D, grouping elements
A with the same string value of attribute B, sorted in the order of ascending of B.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Having a java class A with properties B and C, please
sort a collection of A for B in ascending, and C in descending order.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      What does a following line mean in c#?<br />
      int? x;<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      What is a parser?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      How to issue an error in the xml stylesheet?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      What is a lazy evaluation?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      How do you understand a following sentence?<br />
      For each line of code there should be a comment.<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Have you used any supplemental information to answer
these questions?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
  &lt;item&gt;<br />
    &lt;question&gt;<br />
      Have you independently answered these questions?<br />
    &lt;/question&gt;<br />
    &lt;answer/&gt;<br />
  &lt;/item&gt;<br />
&lt;/questionnaire&gt; 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5dfdbafd-389e-4004-93fe-d50858c7009e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Tuples and maps - Status: CLOSED, WONTFIX</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/07/10/TuplesAndMapsStatusCLOSEDWONTFIX.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,34355851-2d73-446b-86f0-f5abca96914e.aspx</id>
    <published>2008-07-09T22:54:52.954-07:00</published>
    <updated>2008-07-10T01:32:19.3804683-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've found that proposition to introduce <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=34355851-2d73-446b-86f0-f5abca96914e&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d5630" rel="nofollow">tuples
and maps</a> to xslt/xquery type system has not found a support: 
</p>
        <p style="font-style: italic; padding-left: 1em">
At the joint meeting of the XSL and XQuery Working groups 2008-06-23 it was decided
that a change of this nature would be too large for the next "point" release of the
Recommendations. The request for new functionality will be considered for a future
"main" release. 
</p>
        <p>
          <b>Boor&gt;</b> *****!
</p>
        <p>
          <b>Pessimist&gt;</b> Ah, there won't be tuples and maps in xslt/xquery...
</p>
        <p>
          <b>Optimist&gt;</b> Wow, chances are good to see this addition by the year 2018!
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=34355851-2d73-446b-86f0-f5abca96914e" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Update Saxon extensions to reflect v9.1</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/07/03/UpdateSaxonExtensionsToReflectV91.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2f439579-df72-4ea1-9ae7-e127cff9375b.aspx</id>
    <published>2008-07-03T06:47:13.299-07:00</published>
    <updated>2008-07-03T06:49:47.7962195-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today Michael Kay has announced an update for the Saxon processor. The latest version
for now is 9.1. 
</p>
        <p>
I've checked our <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2f439579-df72-4ea1-9ae7-e127cff9375b&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fsaxon.extensions.9.1.zip">saxon.extensions</a>,
and has fixed incompatibilities.
</p>
        <p>
The source for the new version of the Saxon can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2f439579-df72-4ea1-9ae7-e127cff9375b&amp;url=http%3a%2f%2fsaxon.sourceforge.net%2f">http://saxon.sourceforge.net/</a>.
</p>
        <p>
New features are discussed at: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2f439579-df72-4ea1-9ae7-e127cff9375b&amp;url=http%3a%2f%2fwww.saxonica.com%2fdocumentation%2fchanges%2fintro.html">http://www.saxonica.com/documentation/changes/intro.html</a></p>
        <p>
Our extensions can be found at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=2f439579-df72-4ea1-9ae7-e127cff9375b&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fsaxon.extensions.9.1.zip">saxon.extensions.9.1.zip</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2f439579-df72-4ea1-9ae7-e127cff9375b" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Try/catch block in xslt 2.0 for Saxon 9.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/06/26/TrycatchBlockInXslt20ForSaxon9.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,e394e0b8-d3c2-4261-aba9-c70ed03dea1d.aspx</id>
    <published>2008-06-26T02:18:50.749-07:00</published>
    <updated>2008-06-26T23:48:49.1392048-07:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="html">  &lt;p&gt;
We are designing a rather complex xslt 2.0 application, dealing with semistructured
data. We must tolerate with errors during processing, as there are cases where an
input is not perfectly valid (or the program is not designed or ready to get such
an input).
&lt;/p&gt;
&lt;p&gt;
The most typical error is unsatisfied expectation of tree structure like:&lt;br /&gt;
&amp;nbsp; &lt;code&gt;&amp;lt;xsl:variable name=&amp;quot;element&amp;quot; as=&amp;quot;element()&amp;quot; select=&amp;quot;some-element&amp;quot;/&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Obviously, dynamic error occurs if a specified element is not present. To concentrate
on primary logic, and to avoid a burden of illegal (unexpected) case recovery we have
created a try/catch API. The goal of such API is:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
to be able to continue processing in case of error;&lt;/li&gt;
&lt;li&gt;
report as much as possible useful information related to an error.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Alternatives:
&lt;/p&gt;
&lt;p&gt;
Do not think this is our arrogance, which has turned us to create a custom API. No,
we were looking for alternatives! Please see &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d&amp;amp;url=http%3a%2f%2fbiglist.com%2flists%2fxsl-list%2farchives%2f200801%2fthreads.html%2300055"&gt;[xsl]
saxon:try()&lt;/a&gt; discussion:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d&amp;amp;url=http%3a%2f%2fwww.saxonica.com%2fdocumentation%2fextensions%2ffunctions%2ftry.html"&gt;saxon:try()&lt;/a&gt; function
- is a kind of pseudo function, which explicitly relies on lazy evaluation of its
arguments, and ... it&amp;#39;s not available in SaxonB;&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d&amp;amp;url=http%3a%2f%2fwww.fgeorges.org%2fxslt%2ferror-safe%2f"&gt;ex:error-safe&lt;/a&gt;&amp;nbsp;
extension instruction - is far from perfect in its implementation quality, and provides
no error location.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We have no other way except to design this feature by ourselves. In our defence one
can say that we are using innovatory approach that encapsulates details of the implementation
behind template and calls handlers indirectly.
&lt;/p&gt;
&lt;p&gt;
Use:
&lt;/p&gt;
&lt;p&gt;
Try/catch API is designed as a template &lt;code&gt; &amp;lt;xsl:template name=&amp;quot;t:try-block&amp;quot;/&amp;gt&lt;/code&gt; calling
a &amp;quot;try&amp;quot; handler, and, if required, a &amp;quot;catch&amp;quot; hanler using &lt;code&gt; &amp;lt;xsl:apply-templates
mode=&amp;quot;t:call&amp;quot;/&amp;gt;&lt;/code&gt; instruction. Caller passes any information to
these handlers by the means of tunnel parameters.
&lt;/p&gt;
&lt;p&gt;
Handlers must be in a &amp;quot;&lt;code&gt;t:call&lt;/code&gt;&amp;quot; mode. The &amp;quot;catch&amp;quot;
handler may recieve following error info parameters:
&lt;/p&gt;
&lt;p style="padding-left: 1em;"&gt;
&lt;code&gt;&amp;lt;xsl:param name=&amp;quot;error&amp;quot; as=&amp;quot;xs:QName&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;error-description&amp;quot; as=&amp;quot;xs:string&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name=&amp;quot;error-location&amp;quot; as=&amp;quot;item()*&amp;quot;/&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
where &lt;code&gt;$error-location&lt;/code&gt; is a sequence of pairs &lt;code&gt;(location as xs:string,
context as item())*&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
A sample:
&lt;/p&gt;
&lt;p style="padding-left: 1em;"&gt;
&lt;code&gt; &amp;lt;xsl:stylesheet version=&amp;quot;2.0&amp;quot;&lt;br /&gt;
&amp;nbsp; xmlns:xsl=&amp;quot;http://www.w3.org/1999/XSL/Transform&amp;quot;&lt;br /&gt;
&amp;nbsp; xmlns:xs=&amp;quot;http://www.w3.org/2001/XMLSchema&amp;quot;&lt;br /&gt;
&amp;nbsp; xmlns:t=&amp;quot;http://www.nesterovsky-bros.com/xslt/public/&amp;quot;&lt;br /&gt;
&amp;nbsp; exclude-result-prefixes=&amp;quot;xs t&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:include href=&amp;quot;try-block.xslt&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match=&amp;quot;/&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;result&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:for-each select=&amp;quot;1 to 10&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:call-template name=&amp;quot;t:try-block&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:with-param name=&amp;quot;value&amp;quot;
tunnel=&amp;quot;yes&amp;quot; select=&amp;quot;. - 5&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:with-param name=&amp;quot;try&amp;quot;
as=&amp;quot;element()&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;try/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:with-param&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:with-param name=&amp;quot;catch&amp;quot;
as=&amp;quot;element()&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;t:error-handler/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:with-param&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:call-template&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/result&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template mode=&amp;quot;t:call&amp;quot; match=&amp;quot;try&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:param name=&amp;quot;value&amp;quot; tunnel=&amp;quot;yes&amp;quot; as=&amp;quot;xs:decimal&amp;quot;/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;value&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:sequence select=&amp;quot;1 div $value&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/value&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;br /&gt;
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The sample prints values according to the formula &amp;quot;1/(i - 5)&amp;quot;, where &amp;quot;i&amp;quot;
is a variable varying from 1 to 10. Clearly, division by zero occurs when &amp;quot;i&amp;quot;
is equal to 5.
&lt;/p&gt;
&lt;p&gt;
Please notice how to access try/catch API through &lt;code&gt; &amp;lt;xsl:include href=&amp;quot;try-block.xslt&amp;quot;/&amp;gt;&lt;/code&gt;.
The main logic is executed in &lt;code&gt; &amp;lt;xsl:template mode=&amp;quot;t:call&amp;quot; match=&amp;quot;try&amp;quot;/&amp;gt;&lt;/code&gt;,
which recieves parameters using tunneling. A default error handler &lt;code&gt; &amp;lt;t:error-handler/&amp;gt;&lt;/code&gt; is
used to report errors.
&lt;/p&gt;
&lt;p&gt;
Error report:
&lt;/p&gt;
&lt;p style="color: red; padding-left: 1em;"&gt;
&lt;code&gt; Error: FOAR0001&lt;br /&gt;
Description:&lt;br /&gt;
Decimal divide by zero&lt;br /&gt;
&lt;br /&gt;
Location:&lt;br /&gt;
1. systemID: "file:///D:/style/try-block-test.xslt", line: 34&lt;br /&gt;
2. template mode="t:call" match="element(try, xs:anyType)"&lt;br /&gt;
&amp;nbsp; systemID: "file:///D:/style/try-block-test.xslt", line: 30&lt;br /&gt;
&amp;nbsp; context node:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /*[1][local-name() = 'try']&lt;br /&gt;
3. template mode="t:call"&lt;br /&gt;
&amp;nbsp; match="element({http://www.nesterovsky-bros.com/xslt/private/try-block}try,
xs:anyType)"&lt;br /&gt;
&amp;nbsp; systemID: "file:///D:/style/try-block.xslt", line: 53&lt;br /&gt;
&amp;nbsp; context node:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; /*[1][local-name() = 'try']&lt;br /&gt;
4. systemID: "file:///D:/style/try-block.xslt", line: 40&lt;br /&gt;
5. call-template name="t:try-block"&lt;br /&gt;
&amp;nbsp; systemID: "file:///D:/style/try-block-test.xslt", line: 17&lt;br /&gt;
6. for-each&lt;br /&gt;
&amp;nbsp; systemID: "file:///D:/style/try-block-test.xslt", line: 16&lt;br /&gt;
&amp;nbsp; context item: 5 
&lt;br /&gt;
7. template mode="saxon:_defaultMode" match="document-node()"&lt;br /&gt;
&amp;nbsp; systemID: "file:///D:/style/try-block-test.xslt", line: 14&lt;br /&gt;
&amp;nbsp; context node:&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; / &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Implementation details:
&lt;/p&gt;
&lt;p&gt;
You were not expecting this API to be pure xslt, weren&amp;#39;t you? &lt;img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif"&gt;
&lt;/p&gt;
&lt;p&gt;
Well, you&amp;#39;re right, there is an extension function. Its pseudo code is like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em;"&gt;
&lt;code&gt;function tryBlock(tryItems, catchItems) 
&lt;br /&gt;
{ 
&lt;br /&gt;
&amp;nbsp; try&lt;br /&gt;
&amp;nbsp; { 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; execute xsl:apply-templates for tryItems. 
&lt;br /&gt;
&amp;nbsp; }&lt;br /&gt;
&amp;nbsp; catch&lt;br /&gt;
&amp;nbsp; {&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; execute xsl:apply-templates for catchItems. 
&lt;br /&gt;
&amp;nbsp; } 
&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
The last thing. Please get the implementation &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fsaxon.extensions.zip"&gt; saxon.extensions.zip&lt;/a&gt;.
There you will find sources of the try/catch, and &lt;a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d&amp;amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f05%2f18%2fTuplesAndMapsInSaxon.aspx"&gt;tuples/maps&lt;/a&gt; API.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=e394e0b8-d3c2-4261-aba9-c70ed03dea1d" /&gt;</content>
  </entry>
  <entry>
    <title>A "resource:" protocol to resolve documents in xslt.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/06/17/AResourceProtocolToResolveDocumentsInXslt.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cbd8e06a-80d4-42ae-90c1-80d8bfd3a567.aspx</id>
    <published>2008-06-17T00:57:52.395-07:00</published>
    <updated>2008-06-17T22:49:47.7828784-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Right now we're inhabiting in the java world, thus all our tasks are (in)directly
related to this environment.
</p>
        <p>
We want to store stylesheets as resources of java application, and at the same time
to point to these stylesheets without jar qualification. In .NET this idea would not
appear at all, as there are well defined boundaries between assemblies, but java uses
rather different approach. Whenever you have a resource name, it's up to <code>ClassLoader</code> to
find this resource. To exploit this feature we've created an uri resolver for
the stylesheet transformation. The protocol we use has a following format: "<code>resource:/resource-path</code>".
</p>
        <p>
For example to store stylesheets in the <code>META-INF/stylesheets</code> folder we
use uri "<code>resource:/META-INF/stylesheets/java/main.xslt</code>". Relative path
is resolved naturally. A path "<code><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cbd8e06a-80d4-42ae-90c1-80d8bfd3a567&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f06%2f09%2fjxomUpdate.aspx">../jxom/java-serializer.xslt</a></code>"
in previously mentioned stylesheet is resolved to "<code><a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=cbd8e06a-80d4-42ae-90c1-80d8bfd3a567&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f16%2fXsltForTheJxomJavaXmlObjectModel.aspx">resource:/META-INF/stylesheets/jxom/java-serializer.xslt</a></code>". 
</p>
        <p>
We've created a small class <code>ResourceURIResolver</code>. You need to supply an
instance of <code>TransformerFactory</code> with this resolver:<br /><code>  transformerFactory.setURIResolver(new ResourceURIResolver());</code></p>
        <p>
The class itself is so small that we qoute it here:
</p>
        <p style="font-family: monospace; padding-left: 1em;">
import java.io.InputStream;<br /><br />
import java.net.URI;<br />
import java.net.URISyntaxException;<br /><br />
import javax.xml.transform.Source;<br />
import javax.xml.transform.TransformerException;<br />
import javax.xml.transform.URIResolver;<br /><br />
import javax.xml.transform.stream.StreamSource;<br /><br />
/**<br />
 * This class implements an interface that can be called by the processor<br />
 * to turn a URI used in document(), xsl:import, or xsl:include into a<br />
 * Source object.<br />
 */<br />
public class ResourceURIResolver implements URIResolver<br />
{<br />
  /**<br />
   * Called by the processor when it encounters 
<br />
   * an xsl:include, xsl:import, or document() function.<br />
   *<br />
   * This resolver supports protocol "resource:".<br />
   * Format of uri is: "resource:/resource-path", where "resource-path"
is an<br />
   * argument of a {@link ClassLoader#getResourceAsStream(String)} call.<br />
   * @param href - an href attribute, which may be relative or absolute.<br />
   * @param base - a base URI against which the first argument will be made<br />
   *   absolute if the absolute URI is required.<br />
   * @return a Source object, or null if the href cannot be resolved, and<br />
   *   the processor should try to resolve the URI itself.<br />
   */<br />
  public Source resolve(String href, String base)<br />
    throws TransformerException<br />
  {<br />
    if (href == null)<br />
    {<br />
      return null;<br />
    }<br /><br />
    URI uri;<br /><br />
    try<br />
    {<br />
      if (base == null)<br />
      {<br />
        uri = new URI(href);<br />
      } 
<br />
      else 
<br />
      {<br />
        uri = new URI(base).resolve(href); 
<br />
      }<br />
    } 
<br />
    catch(URISyntaxException e) 
<br />
    { 
<br />
      // Unsupported uri.<br />
      return null; 
<br />
    } 
<br /><br />
    if (!"resource".equals(uri.getScheme()))<br />
    {<br />
      return null;<br />
    } 
<br /><br />
    String resourceName = uri.getPath(); 
<br /><br />
    if ((resourceName == null) || (resourceName.length() == 0))<br />
    {<br />
      return null;<br />
    }<br /><br />
    if (resourceName.charAt(0) == '/')<br />
    {<br />
      resourceName = resourceName.substring(1);<br />
    }<br /><br />
    ClassLoader classLoader = Thread.currentThread().getContextClassLoader();<br />
    InputStream stream = classLoader.getResourceAsStream(resourceName);<br /><br />
    if (stream == null)<br />
    {<br />
      return null;<br />
    }<br /><br />
    return new StreamSource(stream, uri.toString()); 
<br />
  }<br />
}
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cbd8e06a-80d4-42ae-90c1-80d8bfd3a567" />
      </div>
    </content>
  </entry>
  <entry>
    <title>jxom update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/06/09/jxomUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,97e1ed84-de44-4c36-9a7b-2bfaa994697a.aspx</id>
    <published>2008-06-08T23:47:54.444-07:00</published>
    <updated>2008-08-01T23:10:07.7268109-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
We've uploaded an <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=97e1ed84-de44-4c36-9a7b-2bfaa994697a&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">update
for the jxom</a>.
</p>
        <p>
It has turned out that jxom schema is so powerful that you can do a great number of
manipulations over xml representation of java program.
</p>
        <p>
In our case this is an optimization of unreachable code, defined at <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=97e1ed84-de44-4c36-9a7b-2bfaa994697a&amp;url=http%3a%2f%2fjava.sun.com%2fdocs%2fbooks%2fjls%2fsecond_edition%2fhtml%2fstatements.doc.html%23236365" rel="nofollow">Sun's
spec</a>. We're facing this problem as result of translation from other ancient language,
which also has well defined xml schema.
</p>
        <p>
We also have introduced an ability to annotate jxom elements (see meta element), which
in practice we use to annotate expressions with their types and perform "compile time"
expression evaluation.
</p>
        <p>
You may <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=97e1ed84-de44-4c36-9a7b-2bfaa994697a&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">download
jxom version at usual place</a>.
</p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=97e1ed84-de44-4c36-9a7b-2bfaa994697a&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f09%2fJavaXmlObjectModel.aspx">Java
Xml Object Model</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=97e1ed84-de44-4c36-9a7b-2bfaa994697a" />
      </div>
    </content>
  </entry>
  <entry>
    <title>JSF 1.2 and java.sql.Date bean properties.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/30/JSF12AndJavasqlDateBeanProperties.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8696e822-24e5-4931-8c51-0f0f600cd130.aspx</id>
    <published>2008-05-30T05:49:50.002-07:00</published>
    <updated>2008-07-07T20:20:45.0810677-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The project we're working on requires us to generate a java web application from a
some ancient language. The code being converted, we have transformed into java classes
(thanks to <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8696e822-24e5-4931-8c51-0f0f600cd130&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f02%2f16%2fXsltForTheJxomJavaXmlObjectModel.aspx">jxom</a>),
the presentation is converted into JSF (facelets) pages.
</p>
        <p style="font-style: italic">
By the way, long before java (.net) platform has been conceived, there were languages
and environments, worked out so good that contemporary client - server paradigms (like
JSF, ASP.NET, and so on) are just their isomorphisms.
</p>
        <p>
The problem we were dealing with recently is JSF databinding for a bean properties
of types <code>java.sql.Date, java.sql.Time, java.sql.Timestamp</code>.
</p>
        <p>
At some point of design we have decided that these types are most natural representation
of data in the original language, as the program's activity is tightly connected
to the database. Later on it's became clear that JSF databinding does not like
these types at all. We were to decide either to fall back and use <code>java.util.Date</code> as
bean property types, or do something with databinding.
</p>
        <p>
It was not clear what's the best way until we have found an elegant solution,
namely: to create ELResolver to handle bean properties of these types. The solution
works because custom el resolvers are applied before standard resolvers (except implicit
one).
</p>
        <p>
The class <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8696e822-24e5-4931-8c51-0f0f600cd130&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjsf1.2%2fDateELResolver.java.txt" target="_blank">DateELResolver</a> is
rather simple extension of the BeanELResolver. To use it you only need to register
it the faces-config.xml:
</p>
        <p style="font-family: monospace; padding-left: 1em;">
&lt;faces-config version="1.2"<br />
  xmlns="http://java.sun.com/xml/ns/javaee"<br />
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<br />
  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee<br />
    http://java.sun.com/xml/ns/javaee/web-facesconfig_1_2.xsd"&gt;<br />
  &lt;application&gt;<br />
    &lt;el-resolver&gt;<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=8696e822-24e5-4931-8c51-0f0f600cd130&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjsf1.2%2fDateELResolver.java.txt" target="_blank">com.nesterovskyBros.jsf.DateELResolver</a>&lt;/el-resolver&gt;<br />
  &lt;/application&gt;<br />
&lt;/faces-config&gt;
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8696e822-24e5-4931-8c51-0f0f600cd130" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Tuples and maps in Saxon</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/18/TuplesAndMapsInSaxon.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,261fb587-c621-41e1-b0ac-3a722f7ab5f6.aspx</id>
    <published>2008-05-18T01:44:09.451-07:00</published>
    <updated>2008-09-05T10:59:15.4662919-07:00</updated>
    <category term="Announce" label="Announce" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,Announce.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently I've proposed to add two new atomic types <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f04%2f04%2fWhatImMissingInXslt20xquery10.aspx"> tuple
and map</a> to the xpath/xslt/xquery type system (see "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6&amp;url=http%3a%2f%2fwww.w3.org%2fBugs%2fPublic%2fshow_bug.cgi%3fid%3d5630">Tuples
an maps</a>"). Later I've implemented <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2f2008%2f04%2f05%2fTupleAndMapInTheXslt20.aspx"> tuple
and map pure xslt approximation</a>. Now I want to present <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fsaxon.extensions.9.1.zip">java
implementation for Saxon</a>.
</p>
        <p>
I've created TupleValue and MapValue atomic types, and Collections class exposing
extension functions api. It's easy to use this api. I'll repeat an example
that I was showing earlier:
</p>
        <p style="padding-left: 1em">
          <code> &lt;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:f="http://www.nesterovsky-bros.com/xslt/functions/public"<br />
  xmlns:p="http://www.nesterovsky-bros.com/xslt/functions/private" 
<br />
  xmlns:c="java:com.nesterovskyBros.saxon.Functions" 
<br />
  exclude-result-prefixes="xs f p c"&gt;<br /><br />
&lt;xsl:template match="/"&gt; 
<br />
   &lt;root&gt;<br />
     &lt;xsl:variable name="tuples" as="item()*"
select="<br />
       for $i in 1 to 20<br />
         return c:tuple(1 to $i)"/&gt;<br /><br />
    &lt;total-items&gt;<br />
      &lt;xsl:sequence select="<br />
        sum<br />
        (<br />
          for $tuple in $tuples return<br />
            count(c:tuple-items($tuple))<br />
        )"/&gt;<br />
    &lt;/total-items&gt;<br />
    &lt;tuples-size&gt;<br />
      &lt;xsl:sequence select="count($tuples)"/&gt;<br />
    &lt;/tuples-size&gt;<br />
    &lt;sums-per-tuples&gt;<br />
      &lt;xsl:for-each select="$tuples"&gt;<br />
        &lt;xsl:variable name="index"
as="xs:integer" select="position()"/&gt;<br /><br />
        &lt;sum index="{$index}" value="{sum(c:tuple-items(.))}"/&gt;<br />
      &lt;/xsl:for-each&gt;<br />
    &lt;/sums-per-tuples&gt;<br /><br />
    &lt;xsl:variable name="cities" as="element()*"&gt;<br />
      &lt;city name="Jerusalem" country="Israel"/&gt;<br />
      &lt;city name="London" country="Great
Britain"/&gt;<br />
      &lt;city name="Paris" country="France"/&gt;<br />
      &lt;city name="New York" country="USA"/&gt;<br />
      &lt;city name="Moscow" country="Russia"/&gt;<br />
      &lt;city name="Tel Aviv" country="Israel"/&gt;<br />
      &lt;city name="St. Petersburg" country="Russia"/&gt;<br />
     &lt;/xsl:variable&gt;<br /><br />
    &lt;xsl:variable name="map" as="item()" select="<br />
      c:map<br />
      (<br />
        for $city in $cities return<br />
        (<br />
          $city/string(@country),<br />
          $city<br />
        )<br />
      )"/&gt;<br /><br />
    &lt;xsl:for-each select="c:map-keys($map)"&gt;<br />
      &lt;xsl:variable name="key" as="xs:string"
select="."/&gt;<br /><br />
      &lt;country name="{$key}"&gt;<br />
        &lt;xsl:sequence select="c:map-value($map,
$key)"/&gt;<br />
     &lt;/country&gt;<br />
    &lt;/xsl:for-each&gt;<br />
  &lt;/root&gt; 
<br />
&lt;/xsl:template&gt; 
<br /><br />
&lt;/xsl:stylesheet&gt;</code>
        </p>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fsaxon.extensions.9.1.zip">Download
java source</a>.
</p>
        <p>
P.S. I would wish this api be integrated into Saxon, as at present java extension
functions are called through reflection.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=261fb587-c621-41e1-b0ac-3a722f7ab5f6" />
      </div>
    </content>
  </entry>
  <entry>
    <title>The best book I ever read.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/15/TheBestBookIEverRead.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,61ab6d44-d150-4d1e-8cf2-7387dd1a4108.aspx</id>
    <published>2008-05-14T23:22:57.975-07:00</published>
    <updated>2008-05-15T08:34:54.6388481-07:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Many times I was tempted to create my bests books list. 
</p>
        <p>
No, I dare not to create it. There are so many brilliant masterpieces; I allow to
make such lists to someone, who is wiser than myself. However, I cannot be silent
about a book I've read recently. This is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=61ab6d44-d150-4d1e-8cf2-7387dd1a4108&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fUlysses_%252528novel%252529" rel="nofollow"> Ulysses</a> by <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=61ab6d44-d150-4d1e-8cf2-7387dd1a4108&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fJames_Joyce" rel="nofollow"> James
Joyce</a>.
</p>
        <p>
It's hard reading: you need to know all creative work of Joyce, Homer, state of
the affairs in the world in the year of 1904, map of city of Dublin in that year,
and many many other information. That is the reason why you must read annotated version.
</p>
        <p>
The labour of reading is compensated with intellectual pleasure from it, because it's
not a story that is catching you, but narration. Having imagination, you're immersing
into a world created by the author.
</p>
        <p>
I can believe that there are people for years living in the world created by Joyce.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=61ab6d44-d150-4d1e-8cf2-7387dd1a4108" />
      </div>
    </content>
  </entry>
  <entry>
    <title>On "XProc: An XML Pipeline Language"</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/12/OnXProcAnXMLPipelineLanguage.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6923dbd6-213a-41c9-a3f8-8a83f56bc368.aspx</id>
    <published>2008-05-12T00:11:58.6490705-07:00</published>
    <updated>2008-05-12T00:11:58.6490705-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I've found another new language (working draft in fact). It's <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6923dbd6-213a-41c9-a3f8-8a83f56bc368&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxproc%2f">an
XML Pipeline Language</a>.
</p>
        <div style="font-style: italic; padding-left: 1em">
          <p>
XProc: An XML Pipeline Language, a language for describing operations to be performed
on XML documents.
</p>
          <p>
An XML Pipeline specifies a sequence of operations to be performed on zero or more
XML documents. Pipelines generally accept zero or more XML documents as input and
produce zero or more XML documents as output. Pipelines are made up of simple steps
which perform atomic operations on XML documents and constructs similar to conditionals,
iteration, and exception handlers which control which steps are executed.
</p>
        </div>
        <p>
An experience shows a process of language invention is an essential part of computer
industry from the very beginning, however...
</p>
        <p>
I must confess I must be too reluctant to any new language: I was happy with C++,
but then all these new languages like Delphi, Java, C#, and so many others started
to appear. It's correct to say that there is no efficient universal language,
however I think it's wrong to say that a domain specific language is required
to solve a particular problem in a most efficient way.
</p>
        <p>
And now a question to the point: why do you need a new language for describing operations
to be performed on XML documents?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6923dbd6-213a-41c9-a3f8-8a83f56bc368" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Xslt 2.0 document pool api, for Saxon</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/09/Xslt20DocumentPoolApiForSaxon.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6356bdaa-72dc-4ad8-8d37-8b5698a8d61d.aspx</id>
    <published>2008-05-08T23:58:29.623-07:00</published>
    <updated>2008-05-17T07:44:23.3009429-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <div style="float: right">
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6356bdaa-72dc-4ad8-8d37-8b5698a8d61d&amp;url=http%3a%2f%2fen.wikipedia.org%2fwiki%2fRibbon_of_Saint_George" rel="nofollow">
            <img alt="Георгиевская ленточка" src="http://www.nesterovsky-bros.com/images/Ribbon_of_Saint_George.png" style="border: 0" />
          </a>
        </div>
        <p>
A project I'm currently working on, requires me to manipulate with a big number
of documents. This includes accessing these documents with key() function.
</p>
        <p>
I never thought this task poses any problem, until I've discovered that Saxon
caches documents loaded using document() function to preserve their identities:
</p>
        <div style="padding-left: 1em; font-style: italic">
          <p>
By default, this function is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6356bdaa-72dc-4ad8-8d37-8b5698a8d61d&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxquery-operators%2f%23stable" rel="nofollow">·stable·</a>.
Two calls on this function return the same document node if the same URI Reference
(after resolution to an absolute URI Reference) is supplied to both calls. Thus, the
following expression (if it does not raise an error) will always be true:
</p>
          <div>
            <pre style="font-style: normal">doc("foo.xml") is doc("foo.xml")
</pre>
          </div>
          <p>
However, for performance reasons, implementations may provide a user option to evaluate
the function without a guarantee of stability. The manner in which any such option
is provided is implementation-defined. If the user has not selected such an option,
a call of the function must either return a stable result or must raise an error:
[<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6356bdaa-72dc-4ad8-8d37-8b5698a8d61d&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxquery-operators%2f%23ERRFODC0003" rel="nofollow">err:FODC0003</a>].
</p>
        </div>
        <p>
Saxon provides a saxon:discard-document() function to release documents from cache.
The use case is like this:
</p>
        <div style="padding-left: 1em;">
          <p>
&lt;xsl:variable name="document" as="document-node()"<br />
   select="saxon:discard-document(document(...))"/&gt;
</p>
        </div>
        <p>
You may see, that saxon:discard-document() is bound to a place where document is loaded.
In my case this is inefficient, as my code repeatedly accesses documents from different
places. To release loaded documents I need to collect them after main processing.
</p>
        <p>
Other issue in Saxon is that, processor may keep document references through xsl:key,
thus saxon:discard-document() provides no guaranty of documents to be garbage collected.
</p>
        <p>
To deal with this, I've designed (Saxon specific) api to manage document pools:
</p>
        <div style="padding-left: 1em; font-family: monospace">
          <p>
            <b>t:begin-document-pool-scope()</b> as item()<br />
  Begins document pool scope.<br />
    Returns scope id.<br /><br /><b>t:end-document-pool-scope(</b>scope as item()<b>)</b><br />
  Terminates document pool scope.<br />
    $scope - scope id.<br /><br /><b>t:put-document-in-pool(</b>document as document-node()<b>)</b> as document-node()<br />
  Puts a document into a current scope of document pool.<br />
    $document - a document to put into the document pool.<br />
    Returns the same document node.
</p>
        </div>
        <p>
The use case is:
</p>
        <div style="padding-left: 1em; font-family: monospace">
&lt;xsl:variable name="scope" select="t:begin-document-pool-scope()"/&gt;<br /><br />
&lt;xsl:sequence select="t:assert($scope)"/&gt;<br /><br />
...<br />
&lt;xsl:variable name="document" as="document-node()"<br />
  select="t:put-document-in-pool(...)"/&gt;<br />
...<br /><br />
&lt;xsl:sequence select="t:end-document-pool-scope($scope)"/&gt;<br /><br /></div>
        <p>
Download <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=6356bdaa-72dc-4ad8-8d37-8b5698a8d61d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fdocument-pool.xslt"> document-pool.xslt</a> to
use this api.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6356bdaa-72dc-4ad8-8d37-8b5698a8d61d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Another difference between tamplates and functions in the xslt 2.0</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/05/03/AnotherDifferenceBetweenTamplatesAndFunctionsInTheXslt20.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d383fc9d-76f4-42b6-931d-ff2842390e1c.aspx</id>
    <published>2008-05-03T09:36:38.708-07:00</published>
    <updated>2008-05-03T20:27:30.7293059-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was already writing about the logical <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2c01c7cb84-f4fa-4219-95aa-54c07fb45ebc.aspx"> difference
between tamplates and functions</a>. This time I've realized another, technical
one. It's related to lazy evaluation, permitted by language specification.
</p>
        <p>
I was arguing as follows: 
</p>
        <ul>
          <li>
suppose you define a function returning a sequence;</li>
          <li>
this function at final step constructs document using xsl:result-document;</li>
          <li>
caller invokes this function and uses only first item of sequence;</li>
          <li>
lazy evaluation allows to xslt processor to calculate first item only, thus <i><b>to
avoid creation of output document altogether</b></i>.</li>
        </ul>
        <p>
This conclusion looked ridiculous to me, as it means that I cannot reliably expect
creation of documents built with xsl:result-document instruction.
</p>
        <p>
To resolve the issue I've checked specification. Someone has already thought of
this. This is what specification says:
</p>
        <div style="padding-left: 1em; font-style: italic;">
          <p>
[Definition: Each instruction in the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-stylesheet">stylesheet</a> is
evaluated in one of two possible <b>output states</b>: <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-final-output-state">final
output state</a> or <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-temporary-output-state">temporary
output state</a>].
</p>
          <p>
[Definition: The first of the two <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-output-state">output
states</a> is called <b>final output</b> state. This state applies when instructions
are writing to a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-final-result-tree">final
result tree</a>.]
</p>
          <p>
[Definition: The second of the two <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-output-state">output
states</a> is called <b>temporary output</b> state. This state applies when instructions
are writing to a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-temporary-tree">temporary
tree</a> or any other non-final destination.]
</p>
          <p>
The instructions in the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-initial-template"> initial
template</a> are evaluated in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-final-output-state">final
output state</a>. An instruction is evaluated in the same <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-output-state">output
state</a> as its calling instruction, except that <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-variable"><code> xsl:variable</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-param"><code>xsl:param</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-with-param"><code>xsl:with-param</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-attribute"><code>xsl:attribute</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-comment"><code>xsl:comment</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-processing-instruction"><code>xsl:processing-instruction</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-namespace"><code>xsl:namespace</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-value-of"><code>xsl:value-of</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-function"><code>xsl:function</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-key"><code>xsl:key</code></a>, <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-sort"><code> xsl:sort</code></a>,
and <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-message"><code>xsl:message</code></a> always
evaluate the instructions in their contained <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-sequence-constructor">sequence
constructor</a> in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-temporary-output-state">temporary
output state</a>.
</p>
          <p>
[ERR XTDE1480] It is a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-nonrec-dynamic-error">non-recoverable
dynamic error</a> to evaluate the <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23element-result-document"><code>xsl:result-document</code></a> instruction
in <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxslt20%2f%23dt-temporary-output-state">temporary
output state</a>.
</p>
        </div>
        <p>
As you can see, xsl:function is always evaluated in temporary output state, and cannot
contain xsl:result-document, in contrast to xsl:template, which may be evaluated in
final output state. This difference dictates the role of templates as a "top
level functions" and functions as standalone algorithms.
</p>
        <p>
You can find more on subject at "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c&amp;url=http%3a%2f%2fsourceforge.net%2fforum%2fmessage.php%3fmsg_id%3d4942414">Lazy
evaluation and predicted results</a>".
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d383fc9d-76f4-42b6-931d-ff2842390e1c" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Multithreading in the xslt 2.0/xquery 1.0 world.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/30/MultithreadingInTheXslt20xquery10World.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5207255f-88ed-4042-8ef4-d504e04d9b5d.aspx</id>
    <published>2008-04-29T23:59:29.499-07:00</published>
    <updated>2008-05-02T03:34:22.5661343-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the era of parallel processing it's so natural to inscribe your favorite programming
language in the league of "Multithreading supporter". I've seen such
appeals before "<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5207255f-88ed-4042-8ef4-d504e04d9b5d&amp;url=http%3a%2f%2fdnovatchev.spaces.live.com%2fblog%2fcns!44B0A32C2CCF7488!385.entry">Wide
Finder in XSLT --&gt; deriving new requirements for efficiency in XSLT processors.</a>"
</p>
        <div style="padding-left: 1em; font-style: italic;">
          <p>
... I am not aware of any XSLT implementation that provides explicit or implicit support
for parallel processing (with the obvious goal to take advantage of the multi-core
processors that have almost reached a "prevalent" status today) ...
</p>
        </div>
        <p>
I think both xslt and xquery are well fitted for parrallel processing in terms of
type system. This is because of "immutable" nature (<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5207255f-88ed-4042-8ef4-d504e04d9b5d&amp;url=http%3a%2f%2fwww.w3.org%2fTR%2fxquery-update-10%2f">until
recent additions</a>) of the execution state, which prevents many race conditions.
The only missing ingredients are <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=5207255f-88ed-4042-8ef4-d504e04d9b5d&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2ca7c64c9e-75e7-4fa0-8709-9f05da0b40a4.aspx">indirect
function call</a>, and a couple of core functions to queue parallel tasks.
</p>
        <p>
Suppose there is a type to encapsulate a function call (say function-id), and a function
accepting a sequence and a function-id. This function calls function-id for each element
of the sequence in a parallel way, and then combines a final result, as if it were
implemented serially.
</p>
        <p>
Pretty simple, isn't it?
</p>
        <p style="PADDING-LEFT: 1em; FONT-FAMILY: monospace">
&lt;!--<br />
  This function runs $id function for each item in a sequence.<br />
    $items - items to process.<br />
    $id - function id.<br />
    Returns a sequece of results of calls to $id function.<br />
--&gt;<br />
&lt;xsl:function name="x:queue-tasks" as="items()*"&gt;<br />
  &lt;xsl:param name="items" as="item()*"/&gt;<br />
  &lt;xsl:param name="id" as="x:function-id"/&gt;<br /><br />
  &lt;!-- The pseudo code. --&gt;<br />
  &lt;xsl:sequence select="$items/call $id (.)"/&gt;<br />
&lt;/xsl:function&gt;
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5207255f-88ed-4042-8ef4-d504e04d9b5d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>On the duty</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/27/OnTheDuty.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,22c6b266-231d-4374-843a-e3be55444a5d.aspx</id>
    <published>2008-04-27T07:54:39.463-07:00</published>
    <updated>2008-04-27T21:11:25.2970181-07:00</updated>
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
For the last several weeks I was on my military duty. We were patrolling Israeli border
near the Egypt. It was a completely different world, world of guns, Hummers, heat
sensors... 
</p>
        <p>
There I've met my army friends. It was fun to listen stories they were telling.
At some point I've started to realize that I'm growing older. Most of my friends
are married and have two or three children.
</p>
        <p>
It seems, this was the genuine world, and my own one is fictitious.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=22c6b266-231d-4374-843a-e3be55444a5d" />
      </div>
    </content>
  </entry>
  <entry>
    <title>MQ connection pool in .NET</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/05/MQConnectionPoolInNET.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,004b4d1f-e75b-4343-ba41-2310fbbc07fc.aspx</id>
    <published>2008-04-05T13:55:57.372-07:00</published>
    <updated>2008-04-06T02:38:32.1808741-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Does WebSphere MQ library for .NET support a connection pool? This is the question,
which ask many .NET developers who deal with IBM WebSphere MQ and write multithread
applications. The answer to this question unfortunately is <b>NO</b>… The .NET version
supports only individual connection types.
</p>
        <p>
I have compared two MQ libraries Java's and one for .NET, and I’ve found that most
of the classes have the same declarations except one crucial for me difference. As
opposed to .NET, the Java MQ library provides several classes implementing MQ connection
pooling. There is nothing similar in .NET library.
</p>
        <p>
There are few common workarounds for this annoying restriction. One of such workarounds
(is recommended by IBM in their <b><i>“MQ using .NET”</i></b>) is to keep open one
MQ connection per thread. Unfortunately such approach is not working for ASP.NET applications
(including web services).
</p>
        <p>
The good news is that starting from service pack 5 for MQ 5.3, and of course for MQ
6.xx they are supporting sharing MQ connections in blocked mode:
</p>
        <p style="font-size: smaller;">
          <i> “The implementation of WebSphere MQ .NET ensures that, for a given connection
(MQQueueManager object instance), all access to the target WebSphere MQ queue manager
is synchronized. The default behavior is that a thread that wants to issue a call
to a queue manager is blocked until all other calls in progress for that connection
are complete.”</i>
        </p>
        <p>
This allows creating an MQ connection (pay attention that MQQueueManager object is
a wrapper for MQ connection) in one thread and exclusive use it in another thread
without side-effects caused by multithreading.
</p>
        <p>
Taking in account this feature, I’ve created a <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=004b4d1f-e75b-4343-ba41-2310fbbc07fc&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fMQPoolManager.zip">simple
MQ connection pool</a>. It’s ease in use. The main class <b>MQPoolManager</b> has
only two static methods:
</p>
        <p style="font-family: monospace">
          <span style="color: blue; font-weight: bold">public static</span> MQQueueManager Get(<span style="color: blue; font-weight: bold">string</span> QueueManagerName, <span style="color: blue; font-weight: bold">string</span> ChannelName, <span style="color: blue; font-weight: bold">string</span> ConnectionName);
</p>
        <p>
and
</p>
        <p style="font-family: monospace">
          <span style="color: blue; font-weight: bold">public static void</span> Release(<span style="color: blue; font-weight: bold">ref</span> MQQueueManager
queueManager);
</p>
        <p>
The method Get returns MQ queue manager (either existing from pool or newly created
one), and Release returns it to the connection pool. Internally the logic of MQPoolManager
tracks expired connections and do some finalizations, if need.
</p>
        <p>
So, you may use one MQ connection pool per application domain without additional efforts
and big changes in existing applications.
</p>
        <p>
By the way, this approach has allowed us to optimize performance of MQ part considerably
in one of ours projects.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=004b4d1f-e75b-4343-ba41-2310fbbc07fc" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Tuple and map in the xslt 2.0</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/05/TupleAndMapInTheXslt20.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,64010d0a-cc81-4fbb-a286-bb199ac7d911.aspx</id>
    <published>2008-04-05T08:49:03.274-07:00</published>
    <updated>2008-04-05T23:39:54.4613521-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2c55a17359-e2ae-4a7e-8249-92e8266970e2.aspx">Yesterday's</a> idea
has inspired me as much as to create a prototype implementation of map and tuple in
the xslt 2.0.
</p>
        <p>
Definitely I wished these were a built-in types, and were considered as atomic values
for purposes of comparasions and iteration. This way it were possible to create highly
efficient grouping per several fields at once.
</p>
        <p>
This pure implementation (<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fxslt-tuple.zip">xslt-tuple.zip</a>)
is rather scetchy, however it allows to feel what can be done with tuples and maps.
I guess a good example may say more than many other words, so have a pleasure:
</p>
        <p style="font-family: monospace; padding-left: 1em;">
&lt;xsl:stylesheet version="2.0"<br />
  xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
  xmlns:f="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com">http://www.nesterovsky-bros.com/xslt/functions</a>"<br />
  exclude-result-prefixes="xs f"&gt;<br /><br />
  &lt;xsl:include href="tuple.xslt"/&gt;<br />
  &lt;xsl:include href="map.xslt"/&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;root&gt;<br />
      &lt;xsl:variable name="tuples" as="item()*"
select="<br />
        f:tuple<br />
        (<br />
          for $i in 1 to 10 return<br />
            f:tuple(1 to $i)<br />
        )"/&gt;<br /><br />
      &lt;total-items&gt;<br />
        &lt;xsl:sequence select="count($tuples)"/&gt;<br />
      &lt;/total-items&gt;<br />
      &lt;tuples-size&gt;<br />
        &lt;xsl:sequence select="f:tuple-size($tuples)"/&gt;<br />
      &lt;/tuples-size&gt;<br />
      &lt;sums-per-tuples&gt;<br />
        &lt;xsl:for-each select="1 to f:tuple-size($tuples)"&gt;<br />
          &lt;xsl:variable name="index"
as="xs:integer" select="position()"/&gt;<br /><br />
          &lt;sum<br />
            index="{$index}"<br />
            value="{sum(f:tuple-items(f:tuple-item($tuples,
$index)))}"/&gt;<br />
        &lt;/xsl:for-each&gt;<br />
      &lt;/sums-per-tuples&gt;<br /><br />
      &lt;xsl:variable name="cities" as="element()*"&gt;<br />
        &lt;city name="Jerusalem" country="Israel"/&gt;<br />
        &lt;city name="London" country="Great
Britain"/&gt;<br />
        &lt;city name="Paris" country="France"/&gt;<br />
        &lt;city name="New York" country="USA"/&gt;<br />
        &lt;city name="Moscow" country="Russia"/&gt;<br />
        &lt;city name="Tel Aviv" country="Israel"/&gt;<br />
        &lt;city name="St. Petersburg" country="Russia"/&gt;<br />
      &lt;/xsl:variable&gt;<br /><br />
      &lt;xsl:variable name="map" as="item()*"
select="<br />
        f:map<br />
        (<br />
          for $city in $cities return<br />
            ($city/string(@country),
$city)<br />
        )"/&gt;<br /><br />
      &lt;xsl:for-each select="f:map-keys($map)"&gt;<br />
        &lt;xsl:variable name="key" as="xs:string"
select="."/&gt;<br /><br />
        &lt;country name="{$key}"&gt;<br />
          &lt;xsl:sequence select="f:map-value($map,
$key)"/&gt;<br />
        &lt;/country&gt;<br />
      &lt;/xsl:for-each&gt;<br />
    &lt;/root&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt;
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=64010d0a-cc81-4fbb-a286-bb199ac7d911" />
      </div>
    </content>
  </entry>
  <entry>
    <title>What I'm missing in xslt 2.0/xquery 1.0</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/04/WhatImMissingInXslt20xquery10.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,55a17359-e2ae-4a7e-8249-92e8266970e2.aspx</id>
    <published>2008-04-04T06:49:56.659-07:00</published>
    <updated>2008-04-04T12:01:48.6282396-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
The type system of xslt 2.0 is not complete (see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=55a17359-e2ae-4a7e-8249-92e8266970e2&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2cb4b62be5-d7d6-411d-9e78-d18bb86853da.aspx">Sequence
of sequences in xslt 2.0</a>). You cannot perform manipulations over items as you
could do. The reason is in the luck of set based constructs: xslt 2.0 supports sequences,
but not associative maps of items.
</p>
        <p>
If you think that xml can be used as a good approximation of a map, I shan't agree
with you. Xml has an application in a very specific cases only. Maps I'm thinking
of,  would allow associate items by reference, like sequences do.
</p>
        <p>
This opens a perspective to create a state objects, to manage sequence of sequences,
to create cyclic graphs of items, and so on. These maps are richer than what key()
function provides right now, and allow to implement for-each-group in xquery.
</p>
        <p>
Such maps can be modeled with several functions, however I would wish they were built
in:
</p>
        <p>
          <b>f:map(</b>$items as item()*<b>)</b> as item()<br />
Returns a map from a sequence $items of pairs (key, value).
</p>
        <p>
          <b>f:map-items(</b>$map as item()<b>)</b> as item()*<br />
Returns a sequence of pairs (key, value) for a map $map.
</p>
        <p>
          <b>f:map-keys(</b>$map as item()<b>)</b> as item()*<br />
Returns a sequence of keys contained in a map $map.
</p>
        <p>
          <b>f:map-values(</b>$map as item()<b>)</b> as item()*<br />
Returns a sequence of values contained in a map $map.
</p>
        <p>
          <b>f:map-value(</b>$map as item(), $key as item()<b>)</b> as item()*<br />
Returns a sequence of values corresponding to a specified key $key contained a specified
map $map.
</p>
        <p>
The other thing I would add is items tuple. It's like a sequence, however a sequence
of tuples is never transformed into single sequence, but stays as sequence of tuples.
</p>
        <p>
Fortunately it's possible to implement such extension functions.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=55a17359-e2ae-4a7e-8249-92e8266970e2" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Bizarre xslt</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/04/02/BizarreXslt.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,69678336-fbe3-4a96-99fd-f76325a7d329.aspx</id>
    <published>2008-04-01T22:45:28.123-07:00</published>
    <updated>2008-04-01T22:50:27.7544041-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
xslt 2.0 is a beautiful language and at the same time it allows constructs, which
may trouble anyone.
</p>
        <p>
Look at this valid stylesheet:
</p>
        <p style="font-family: monospace; padding-left: 1em;">
&lt;xsl:stylesheet version="2.0"<br />
  xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=69678336-fbe3-4a96-99fd-f76325a7d329&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=69678336-fbe3-4a96-99fd-f76325a7d329&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:variable name="x" as="node()" select="."/&gt;<br />
    &lt;xsl:variable name="x" as="xs:int" select="***"/&gt;<br /><br />
    &lt;xsl:sequence select="$x"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt;
</p>
        <p>
Fun, isn't it? <img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif" /></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=69678336-fbe3-4a96-99fd-f76325a7d329" />
      </div>
    </content>
  </entry>
  <entry>
    <title>functions and named templates in xslt 2.0</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/03/31/functionsAndNamedTemplatesInXslt20.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,01c7cb84-f4fa-4219-95aa-54c07fb45ebc.aspx</id>
    <published>2008-03-30T23:54:22.777-07:00</published>
    <updated>2008-03-31T03:55:14.2117321-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I was thinking earlier about the difference between named tamplates and functions
in xslt 2.0 and have not found satisfactory criterion for a decision of what to use
in each case. I was not first one who has troubled with this, see <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=01c7cb84-f4fa-4219-95aa-54c07fb45ebc&amp;url=http%3a%2f%2fbiglist.com%2flists%2flists.mulberrytech.com%2fxsl-list%2farchives%2f200512%2fmsg00567.html"> stylesheet
functions or named templates</a>.
</p>
        <p>
To feel easy I deliberately have decided to use functions whenever possible, avoid
named tamplates completely, and use matching templates to apply logic depending on
context (something like virtual function). I've forgot about the issue until yesterday.
To realize the difference one should stop thinking of it, quite opposite she must
start solving practical xslt tasks, and if there is any difference, except syntactic,
it will manifest itself somehow.
</p>
        <p>
To make things obvious to those whose programming roots are in a language like C++
I shall compare xsl:function with free standing (or static) C++ function, and named
xsl:template with C++ member function. In C++ you can use both free standing and member
functions interchangeably, however if there is only one argument (among others) whose
state transition this function represents then it's preferrable to define it as
a member function. The most important difference between these two type of functions
is that a member function has hidden argument "this", and is able to access
its private state.
</p>
        <p>
Please, do not try to think I'm going to compare template context item in xslt 2.0
with "this" in C++, quite opposite I consider context item as a part of a state. I'm
arguing however, of private state that can be passed through template call chain with
tunnel parameters. Think of a call tunneling some state (like options, flags, values),
and that state accessed several levels deep in call hierarchy, whenever one needs
to. You cannot do it with xsl:function, you cannot pass all private state through
the function call, you just do not know of it.
</p>
        <p>
This way my answer to the tacit question is:
</p>
        <ul>
          <li>
 use xsl:function to perform independent unit of logic;</li>
          <li>
 use named xsl:template when a functionality is achieved cooperatively, and when
you will possibly need to share the state between different implementation blocks; 
</li>
        </ul>
        <p>
After thinking through this, I've noticed that such distinction does not exist in
XQuery 1.0. There is no tunneling there. <img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif" /></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=01c7cb84-f4fa-4219-95aa-54c07fb45ebc" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Xslt 2.0 tips, public and private stylesheet members</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/03/25/Xslt20TipsPublicAndPrivateStylesheetMembers.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9e65211f-dbff-4ac9-befe-3167351d18be.aspx</id>
    <published>2008-03-24T23:23:30.368-07:00</published>
    <updated>2008-08-04T23:31:52.4490017-07:00</updated>
    <category term="Tips and tricks" label="Tips and tricks" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,TipsAndTricks.aspx" />
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the xslt world there is no widely used custom to think of stylesheet members as
of public and private in contrast to other programming languages like C++/java/c#
where access modifiers are essential. The reason is in complexity of stylesheets:
the less size of code - the easier to developer to keep all details in memory. Whenever
xslt program grows you should modularize it to keep it manageable.
</p>
        <p>
At the point where modules are introduced one starts thinking of public interface
of module and its implementation details. This separation is especially important
for the template matching as you won't probably want to match private template
just because you've forgotten about some template in implementation of some module.
</p>
        <p>
To make public or private member distinction you can introduce two namespaces in your
stylesheet, like:
</p>
        <ul>
          <li>
            <p>
xmlns:t="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2f">http://www.nesterovsky-bros.com/public</a>"
- for public members;
</p>
          </li>
          <li>
            <p>
xmlns:p="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2f">http://www.nesterovsky-bros.com/private/expression.xslt</a>"
- for private members.
</p>
          </li>
        </ul>
        <p>
For the private namespace you can use a unique name, e.g. stylesheet name as part
of uri.
</p>
        <p>
The following example is based on <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2c792f0790-a21e-4388-8e5a-d7e2810e1d31.aspx"> jxom</a>.
This stylesheet builds expression from expression tree. Public part consists only
of t:get-expression function, other members are private:
</p>
        <p style="padding-left: 1em; font-family: monospace">
&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
  xmlns:t="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2f">http://www.nesterovsky-bros.com/public</a>"<br />
  xmlns:p="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2f">http://www.nesterovsky-bros.com/private/expression.xslt</a>"<br />
  xmlns="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">http://www.nesterovsky-bros.com/download/jxom.zip</a>"<br />
  xpath-default-namespace="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">http://www.nesterovsky-bros.com/download/jxom.zip</a>"<br />
  exclude-result-prefixes="xs t p"&gt;<br /><br />
  &lt;xsl:output method="text" indent="yes"/&gt;<br /><br />
  &lt;!-- Entry point. --&gt;<br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:variable name="expression" as="element()"&gt;<br />
      &lt;lt&gt;<br />
        &lt;sub&gt;<br />
          &lt;mul&gt;<br />
            &lt;var name="b"/&gt;<br />
            &lt;var name="b"/&gt;<br />
          &lt;/mul&gt;<br />
          &lt;mul&gt;<br />
            &lt;mul&gt;<br />
              &lt;int&gt;4&lt;/int&gt;<br />
              &lt;var
name="a"/&gt;<br />
            &lt;/mul&gt;<br />
            &lt;var name="c"/&gt;<br />
          &lt;/mul&gt;<br />
        &lt;/sub&gt;<br />
        &lt;double&gt;0&lt;/double&gt;<br />
      &lt;/lt&gt;<br />
    &lt;/xsl:variable&gt;<br /><br />
    &lt;xsl:value-of select="t:get-expression($expression)"
separator=""/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!--<br />
    Gets expression.<br />
      $element - expression element.<br />
      Returns expression tokens.<br />
  --&gt;<br />
  &lt;xsl:function name="t:get-expression" as="item()*"&gt;<br />
    &lt;xsl:param name="element" as="element()"/&gt;<br /><br />
    &lt;xsl:apply-templates mode="p:expression" select="$element"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!--<br />
    Gets binary expression.<br />
      $element - assignment expression.<br />
      $type - expression type.<br />
      Returns expression token sequence.<br />
  --&gt;<br />
  &lt;xsl:function name="p:get-binary-expression" as="item()*"&gt;<br />
    &lt;xsl:param name="element" as="element()"/&gt;<br />
    &lt;xsl:param name="type" as="xs:string"/&gt;<br /><br />
    &lt;xsl:sequence select="t:get-expression($element/*[1])"/&gt;<br />
    &lt;xsl:sequence select="' '"/&gt;<br />
    &lt;xsl:sequence select="$type"/&gt;<br />
    &lt;xsl:sequence select="' '"/&gt;<br />
    &lt;xsl:sequence select="t:get-expression($element/*[2])"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!-- Mode "expression". Empty match. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="@*|node()"&gt;<br />
    &lt;xsl:sequence select="error(xs:QName('invalid-expression'),
name())"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". or. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="or"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '||')"/&gt; 
<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". and. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="and"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '&amp;&amp;')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". eq. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="eq"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '==')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". ne. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="ne"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '!=')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". le. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="le"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '&lt;=')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". ge. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="ge"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '&gt;=')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". lt. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="lt"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '&lt;')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". gt. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="gt"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '&gt;')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". add. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="add"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '+')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". sub. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="sub"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '-')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". mul. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="mul"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '*')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". div. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="div"&gt;<br />
    &lt;xsl:sequence select="p:get-binary-expression(., '/')"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". neg. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="neg"&gt;<br />
    &lt;xsl:sequence select="'-'"/&gt;<br />
    &lt;xsl:sequence select="t:get-expression(*[1])"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". not. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="not"&gt;<br />
    &lt;xsl:sequence select="'!'"/&gt;<br />
    &lt;xsl:sequence select="t:get-expression(*[1])"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". parens. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="parens"&gt;<br />
    &lt;xsl:sequence select="'('"/&gt;<br />
    &lt;xsl:sequence select="t:get-expression(*[1])"/&gt;<br />
    &lt;xsl:sequence select="')'"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". var. --&gt;<br />
  &lt;xsl:template mode="p:expression" match="var"&gt;<br />
    &lt;xsl:sequence select="@name"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!-- Mode "expression". int, short, byte, long, float, double.
--&gt;<br />
  &lt;xsl:template mode="p:expression"<br />
    match="int | short | byte | long | float | double"&gt;<br />
    &lt;xsl:sequence select="."/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
 &lt;/xsl:stylesheet&gt;
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9e65211f-dbff-4ac9-befe-3167351d18be" />
      </div>
    </content>
  </entry>
  <entry>
    <title>xslt/xquery -&gt; java code</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/03/03/xsltxqueryJavaCode.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,aa253615-d461-42aa-8ccb-2a1733557ce6.aspx</id>
    <published>2008-03-03T10:08:21.847-08:00</published>
    <updated>2008-03-03T10:08:54.8000022-08:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I often find myself in a position that whenever I'm thinking of something, I can find
the idea to be already implemented somewhere.
</p>
        <p>
A good example is <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=aa253615-d461-42aa-8ccb-2a1733557ce6&amp;url=http%3a%2f%2fsourceforge.net%2fforum%2fmessage.php%3fmsg_id%3d4808384">xslt/xquery
-&gt; java code</a>.
</p>
        <p>
Well, the world is full with smart guys. <img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif" /></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=aa253615-d461-42aa-8ccb-2a1733557ce6" />
      </div>
    </content>
  </entry>
  <entry>
    <title>jxom - inventing a bicycle?</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/02/28/jxomInventingABicycle.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,48e4d406-68ae-43c0-9a90-491ca782cb4f.aspx</id>
    <published>2008-02-27T20:35:24.018-08:00</published>
    <updated>2008-02-27T20:36:01.5020257-08:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Wow, I've found an article <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=48e4d406-68ae-43c0-9a90-491ca782cb4f&amp;url=http%3a%2f%2fwww.ibm.com%2fdeveloperworks%2fxml%2flibrary%2fx-xslphp1%2f">Code
generation in XSLT 2.0</a>. The article is dated by year 2005.
</p>
        <p>
Well, I was inventing a bicycle. This is a good lesson for me.
</p>
        <p>
I'm going to study very carefully about SQL Code Generation, as this is exacly the
same task I'm facing now.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=48e4d406-68ae-43c0-9a90-491ca782cb4f" />
      </div>
    </content>
  </entry>
  <entry>
    <title>jxom update</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/02/27/jxomUpdate.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ab2ef53d-d091-442f-8c03-7d4e78cdd6b8.aspx</id>
    <published>2008-02-27T05:30:47.284-08:00</published>
    <updated>2008-02-27T06:44:17.0960302-08:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
I've updated <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=ab2ef53d-d091-442f-8c03-7d4e78cdd6b8&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fdownload%2fjxom.zip">jxom.zip</a>.
</p>
        <p>
There are minor fixes there. The most important addition is a line breaker. The
purpose of the line breaker is to split long lines. 
</p>
        <p>
Long lines appear if there are verbose comments, or there is a very long expression,
which was not categorized as multiline.
</p>
        <p>
It's not perfect, however looks acceptable.
</p>
        <p>
Now I'm facing a next problem: I need to do a similar job I'm doing to java,
however with sql. Moreover, I need to support several dialects of sql. I'm not sure
if it's possible (worth) to define single sql-xom.xsd, or should I define sql-db2-v9-xom.xsd,
sql-sqlserver-2005-xom.xsd, ...<br /><br />
The bad news are that sql grammar is much more complex than one of java. Probably
I'll start from some sql subset. In any case I do not consider generation of sql "directly",
as jxom fits remarkably into its role.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ab2ef53d-d091-442f-8c03-7d4e78cdd6b8" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Efficient xslt 2.0 recursion in saxon 9.</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/02/20/EfficientXslt20RecursionInSaxon9.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,eb4bbdac-6546-40c4-a14e-d6692b8bfae4.aspx</id>
    <published>2008-02-20T00:59:22.973-08:00</published>
    <updated>2008-03-12T03:22:28.8451222-07:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Building <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=eb4bbdac-6546-40c4-a14e-d6692b8bfae4&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2c792f0790-a21e-4388-8e5a-d7e2810e1d31.aspx">jxom</a> stylesheets
I've learned what is a "good" and "bad" recursion from the saxon's perspective.
</p>
        <p>
I'm using control tokens $t:indent and $t:unindent to control indentation in the sequence
of tokens defining java output. To build output lines I need to calculate total indentation
for each line. This can be done using cummulative sum, considering $t:indent as +1
and $t:unindent as -1.
</p>
        <p>
This task can be formalized as "calculate cummulative integer sum".
</p>
        <p>
The first approach I've tested is non recursive: "for $i in 1 to count($items) return
sum(subsequence($items, 1, $i))".<br />
It is incredibly slow.
</p>
        <p>
The next try was recurrent: calculate and spew results as they are calculated.<br />
This is "crash fast" method. Saxon, indeed, implements this as recursion and arrives
to a stack limit early.
</p>
        <p>
The last approach, employes saxon's ability to detect some particular flavour of tail
calls. When function contains a tail call, and the output on a tail call code path
consists of this tail call only, then saxon transforms such construction into a cycle.
Thus I need to accumulate result and pass it down to a tail call chain and output
it on the last opportunity only.
</p>
        <p>
The following sample shows this technique:
</p>
        <p style="PADDING-LEFT: 1em; FONT-FAMILY: monospace">
&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=eb4bbdac-6546-40c4-a14e-d6692b8bfae4&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=eb4bbdac-6546-40c4-a14e-d6692b8bfae4&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
  xmlns:t="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=eb4bbdac-6546-40c4-a14e-d6692b8bfae4&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com">http://www.nesterovsky-bros.com</a>"<br />
  exclude-result-prefixes="xs t"&gt;<br /><br />
  &lt;xsl:output method="xml" indent="yes"/&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:variable name="values" as="xs:integer*" select="1 to 10000"/&gt;<br /><br />
    &lt;result&gt;<br />
      &lt;sum&gt;<br />
        &lt;xsl:value-of select="t:cumulative-integer-sum($values)"/&gt;<br /><br />
        &lt;!-- This call crashes with stack overflow.
--&gt;<br />
        &lt;!-- &lt;xsl:value-of select="t:bad-cumulative-integer-sum($values)"/&gt;
--&gt;<br /><br />
        &lt;!-- To compare speed uncomment following
lines. --&gt;<br />
        &lt;!--&lt;xsl:value-of select="sum(t:cumulative-integer-sum($values))"/&gt;--&gt;<br />
        &lt;!--&lt;xsl:value-of select="sum(t:slow-cumulative-integer-sum($values))"/&gt;--&gt;<br />
      &lt;/sum&gt;<br />
    &lt;/result&gt; 
<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!--<br />
    Calculates cumulative sum of integer sequence.<br />
      $items - input integer sequence.<br />
      Returns an integer sequence that is a cumulative sum
of original sequence.<br />
  --&gt;<br />
  &lt;xsl:function name="t:cumulative-integer-sum" as="xs:integer*"&gt;<br />
    &lt;xsl:param name="items" as="xs:integer*"/&gt;<br /><br />
    &lt;xsl:sequence select="t:cumulative-integer-sum-impl($items,
1, 0, ())"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!--<br />
    Implementation of the t:cumulative-integer-sum.<br />
      $items - input integer sequence.<br />
      $index - current iteration index.<br />
      $sum - base sum.<br />
      $result - collected result.<br />
      Returns an integer sequence that is a cumulative sum
of original sequence.<br />
  --&gt;<br />
  &lt;xsl:function name="t:cumulative-integer-sum-impl" as="xs:integer*"&gt;<br />
    &lt;xsl:param name="items" as="xs:integer*"/&gt;<br />
    &lt;xsl:param name="index" as="xs:integer"/&gt;<br />
    &lt;xsl:param name="sum" as="xs:integer"/&gt;<br />
    &lt;xsl:param name="result" as="xs:integer*"/&gt;<br /><br />
    &lt;xsl:variable name="item" as="xs:integer?" select="$items[$index]"/&gt;<br /><br />
    &lt;xsl:choose&gt;<br />
      &lt;xsl:when test="empty($item)"&gt;<br />
        &lt;xsl:sequence select="$result"/&gt;<br />
      &lt;/xsl:when&gt;<br />
      &lt;xsl:otherwise&gt;<br />
        &lt;xsl:variable name="value" as="xs:integer"
select="$item + $sum"/&gt;<br />
        &lt;xsl:variable name="next" as="xs:integer+"
select="$result, $value"/&gt;<br /><br />
        &lt;xsl:sequence select="<br />
          t:cumulative-integer-sum-impl($items,
$index + 1, $value, $next)"/&gt;<br />
      &lt;/xsl:otherwise&gt;<br />
    &lt;/xsl:choose&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!-- "Bad" implementation of the cumulative-integer-sum. --&gt;<br />
  &lt;xsl:function name="t:bad-cumulative-integer-sum" as="xs:integer*"&gt;<br />
    &lt;xsl:param name="items" as="xs:integer*"/&gt;<br /><br />
    &lt;xsl:sequence select="t:bad-cumulative-integer-sum-impl($items,
1, 0)"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!-- "Bad" implementation of the cumulative-integer-sum. --&gt;<br />
  &lt;xsl:function name="t:bad-cumulative-integer-sum-impl" as="xs:integer*"&gt;<br />
    &lt;xsl:param name="items" as="xs:integer*"/&gt;<br />
    &lt;xsl:param name="index" as="xs:integer"/&gt;<br />
    &lt;xsl:param name="sum" as="xs:integer"/&gt;<br /><br />
    &lt;xsl:variable name="item" as="xs:integer?" select="$items[$index]"/&gt;<br /><br />
    &lt;xsl:if test="exists($item)"&gt;<br />
      &lt;xsl:variable name="value" as="xs:integer" select="$item
+ $sum"/&gt;<br />
  
<br />
      &lt;xsl:sequence select="$value"/&gt;<br />
      &lt;xsl:sequence select="<br />
        t:bad-cumulative-integer-sum-impl($items,
$index + 1, $value)"/&gt;<br />
    &lt;/xsl:if&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
 &lt;!-- Non recursive implementation of the cumulative-integer-sum. --&gt;<br />
 &lt;xsl:function name="t:slow-cumulative-integer-sum" as="xs:integer*"&gt;<br />
   &lt;xsl:param name="items" as="xs:integer*"/&gt;<br /><br />
   &lt;xsl:sequence select="<br />
     for $i in 1 to count($items) return<br />
       sum(subsequence($items, 1, $i))"/&gt;<br />
 &lt;/xsl:function&gt;<br /><br />
&lt;/xsl:stylesheet&gt;
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=eb4bbdac-6546-40c4-a14e-d6692b8bfae4" />
      </div>
    </content>
  </entry>
  <entry>
    <title>Sequence of sequences in xslt 2.0</title>
    <link rel="alternate" type="text/html" href="http://www.nesterovsky-bros.com/weblog/2008/02/19/SequenceOfSequencesInXslt20.aspx" />
    <id>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,b4b62be5-d7d6-411d-9e78-d18bb86853da.aspx</id>
    <published>2008-02-18T23:54:11.737-08:00</published>
    <updated>2008-02-19T00:14:23.6832607-08:00</updated>
    <category term="xslt" label="xslt" scheme="http://www.nesterovsky-bros.com/weblog/CategoryView,category,xslt.aspx" />
    <content type="xhtml">
      <div xmlns="http://www.w3.org/1999/xhtml">
        <p>
Comparing xslt 2.0 with its predecessor I see a great evolution of the language. There
are however parts of language, which are not as good as they could be.
</p>
        <p>
Look at manipulations of sequence of sequence of items. xpath 2.0/xquery 1.0 type
system treats type quantifiers separately from type itself. One can declare a
variable of type "xs:string", or variable of type of sequence of strings "xs:string*".
Unfortunately it's not possible to declare a sequence of sequence of strings "xs:string**",
as type can have only one quantifier.
</p>
        <p>
I think this is wrong. People do different tricks to remedy the problem. Typically
one builds nodes that contain copy of items of sequences. Clearly this is
a heavy way to achieve a simple result, moreover it does not preserve item identity.
</p>
        <p>
In <a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b4b62be5-d7d6-411d-9e78-d18bb86853da&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com%2fweblog%2fPermaLink%2cguid%2c792f0790-a21e-4388-8e5a-d7e2810e1d31.aspx">jxom</a> I'm
using different solution to store sequence of sequences, namely storing all sequences
in one, separated with terminator.
</p>
        <p>
A typical sample is in the java serializer. After building method's parameters
I should format them one (compact) or the other (verbose) way depending on decision,
which can be made when all parameters are already built.
</p>
        <p>
To see how it's working please look at following xslt:
</p>
        <p style="PADDING-LEFT: 1em; FONT-FAMILY: monospace">
&lt;?xml version="1.0" encoding="utf-8"?&gt;<br />
&lt;xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b4b62be5-d7d6-411d-9e78-d18bb86853da&amp;url=http%3a%2f%2fwww.w3.org%2f1999%2fXSL%2fTransform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b4b62be5-d7d6-411d-9e78-d18bb86853da&amp;url=http%3a%2f%2fwww.w3.org%2f2001%2fXMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
  xmlns:t="<a href="http://www.nesterovsky-bros.com/weblog/ct.ashx?id=b4b62be5-d7d6-411d-9e78-d18bb86853da&amp;url=http%3a%2f%2fwww.nesterovsky-bros.com">http://www.nesterovsky-bros.com</a>"<br />
  exclude-result-prefixes="xs t"&gt;<br /><br />
  &lt;xsl:output method="xml" indent="yes"/&gt;<br /><br />
  &lt;!-- Terminator token. --&gt;<br />
  &lt;xsl:variable name="t:terminator" as="xs:QName"<br />
    select="xs:QName('t:terminator')"/&gt;<br /><br />
  &lt;!-- New line. --&gt;<br />
  &lt;xsl:variable name="t:crlf" as="xs:string" select="'&amp;#10;'"/&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;!--<br />
      We need to manipulate a sequence of sequence of tokens.<br />
      To do this we use $t:terminator to separate sequences.<br />
    --&gt;<br />
    &lt;xsl:variable name="short-items" as="item()*"&gt;<br />
      &lt;xsl:sequence select="t:get-param('int', 'a')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br /><br />
      &lt;xsl:sequence select="t:get-param('int', 'b')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br /><br />
      &lt;xsl:sequence select="t:get-param('int', 'c')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br />
    &lt;/xsl:variable&gt;<br /><br />
    &lt;xsl:variable name="long-items" as="item()*"&gt;<br />
      &lt;xsl:sequence select="t:get-param('int', 'a')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br /><br />
      &lt;xsl:sequence select="t:get-param('int', 'b')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br /><br />
      &lt;xsl:sequence select="t:get-param('int', 'c')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br /><br />
      &lt;xsl:sequence select="t:get-param('int', 'd')"/&gt;<br />
      &lt;xsl:sequence select="$t:terminator"/&gt;<br />
    &lt;/xsl:variable&gt;<br /><br />
    &lt;result&gt;<br />
      &lt;short&gt;<br />
        &lt;xsl:value-of select="t:format($short-items)"
separator=""/&gt;<br />
      &lt;/short&gt;<br />
      &lt;long&gt;<br />
        &lt;xsl:value-of select="t:format($long-items)"
separator=""/&gt;<br />
      &lt;/long&gt;<br />
    &lt;/result&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!--<br />
    Returns a sequence of tokens that defines a parameter.<br />
      $type - parameter type.<br />
      $name - parameter name.<br />
      Returns sequence of parameter tokens.<br />
  --&gt;<br />
  &lt;xsl:function name="t:get-param" as="item()*"&gt;<br />
    &lt;xsl:param name="type" as="xs:string"/&gt;<br />
    &lt;xsl:param name="name" as="xs:string"/&gt;<br /><br />
    &lt;xsl:sequence select="$type"/&gt;<br />
    &lt;xsl:sequence select="' '"/&gt;<br />
    &lt;xsl:sequence select="$name"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
  &lt;!--<br />
    Format sequence of sequence of tokens separated with $t:terminator.<br />
      $tokens - sequence of sequence of tokens to format.<br />
      Returns formatted sequence of tokens.<br />
  --&gt;<br />
  &lt;xsl:function name="t:format" as="item()*"&gt;<br />
    &lt;xsl:param name="tokens" as="item()*"/&gt;<br /><br />
    &lt;xsl:variable name="terminators" as="xs:integer+"<br />
      select="0, index-of($tokens, $t:terminator)"/&gt;<br />
    &lt;xsl:variable name="count" as="xs:integer"<br