<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:georss="http://www.georss.org/georss" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" version="2.0">
  <channel>
    <title>Nesterovsky bros - xslt</title>
    <link>http://www.nesterovsky-bros.com/weblog/</link>
    <description />
    <language>en-us</language>
    <copyright>Nesterovsky bros</copyright>
    <lastBuildDate>Sun, 08 Jan 2023 13:28:14 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.12105.0</generator>
    <managingEditor>contact@nesterovsky-bros.com</managingEditor>
    <webMaster>contact@nesterovsky-bros.com</webMaster>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=486afbcd-3e16-4240-97c4-3c985d6c6754</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=486afbcd-3e16-4240-97c4-3c985d6c6754</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While doing a migration of some big xslt 3 project into plain C# we run into a case
that was not obvious to resolve.
</p>
        <p>
Documents we process can be from a tiny to a moderate size. Being stored in xml they
might take from virtually zero to, say, 10-20 MB.
</p>
        <p>
In C# we may rewrite Xslt code virtually in one-to-one manner using standard features
like XDocument, LINQ, regular classes, built-in collections, and so on. Clearly C#
has a reacher repertoire, so task is easily solved unless you run into multiple opportunities
to solve it.
</p>
        <p>
The simplest solution is to use XDocument API to represent data at runtime, and use
LINQ to query it. All features like xslt keys, templates, functions, xpath sequences,
arrays and maps and primitive types are natuarally mapped into C# language and its
APIs.
</p>
        <p>
Taking several xslt transformations we could see that xslt to C# rewrite is rather
straightforward and produces recognizable functional programs that have close C# source
code size to their original Xslt. As a bonus C# lets you write code in asynchronous
way, so C# wins in a runtime scalability, and in a design-time support.
</p>
        <p>
But can you do it better in C#, especially when some data has well defined xml schemas?
</p>
        <p>
The natural step, in our opinion, would be to produce C# plain object model from xml
schema and use it for runtime processing. Fortunately .NET has xml serialization attributes
and tools to produce classes from xml schemas. With small efforts we have created
a relevant class hierarchy for a rather big xml schema. XmlSerializer is used to convert
object model to and from xml through XmlReader and XmlWriter. So, we get typed replacement
of generic XDocument that still supports the same LINQ API over collections of objects,
and takes less memory at runtime.
</p>
        <p>
The next step would be to commit a simple test like: 
</p>
        <ul>
          <li>
            <p>
read object model;
</p>
          </li>
          <li>
            <p>
transform it;
</p>
          </li>
          <li>
            <p>
write it back.
</p>
          </li>
        </ul>
        <p>
We have created such tests both for XDocument and for object model cases, and compared
results from different perspectives.
</p>
        <p>
Both solution produce very similar code, which is also similar to original xslt both
in style and size.
</p>
        <p>
Object model has static typing, which is much better to support.
</p>
        <p>
But the most unexpected outcome is that object model was up to 20% slower due to serialization
and deserialization even with pregenerated xmlserializer assemblies. Difference of
transformation performance and memory consumption was so unnoticable that it can be
neglected. These results were confirmed with multiple tests, with multiple cycles
including heating up cycles.
</p>
        <p>
Here we run into a case where static typing harms more than helps. Because of the
nature of our processing pipeline, which is offline batch, this difference can be
mapped into 10th of minutes or even more.
</p>
        <p>
Thus in this particular case we decided to stay with runtime typing as a more performant
way of processing in C#. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=486afbcd-3e16-4240-97c4-3c985d6c6754" />
      </body>
      <title>XDocument vs Plain Object Model</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2023/01/08/XDocumentVsPlainObjectModel.aspx</link>
      <pubDate>Sun, 08 Jan 2023 13:28:14 GMT</pubDate>
      <description>  &lt;p&gt;
While doing a migration of some big xslt 3 project into plain C# we run into a case
that was not obvious to resolve.
&lt;/p&gt;
&lt;p&gt;
Documents we process can be from a tiny to a moderate size. Being stored in xml they
might take from virtually zero to, say, 10-20 MB.
&lt;/p&gt;
&lt;p&gt;
In C# we may rewrite Xslt code virtually in one-to-one manner using standard features
like XDocument, LINQ, regular classes, built-in collections, and so on. Clearly C#
has a reacher repertoire, so task is easily solved unless you run into multiple opportunities
to solve it.
&lt;/p&gt;
&lt;p&gt;
The simplest solution is to use XDocument API to represent data at runtime, and use
LINQ to query it. All features like xslt keys, templates, functions, xpath sequences,
arrays and maps and primitive types are natuarally mapped into C# language and its
APIs.
&lt;/p&gt;
&lt;p&gt;
Taking several xslt transformations we could see that xslt to C# rewrite is rather
straightforward and produces recognizable functional programs that have close C# source
code size to their original Xslt. As a bonus C# lets you write code in asynchronous
way, so C# wins in a runtime scalability, and in a design-time support.
&lt;/p&gt;
&lt;p&gt;
But can you do it better in C#, especially when some data has well defined xml schemas?
&lt;/p&gt;
&lt;p&gt;
The natural step, in our opinion, would be to produce C# plain object model from xml
schema and use it for runtime processing. Fortunately .NET has xml serialization attributes
and tools to produce classes from xml schemas. With small efforts we have created
a relevant class hierarchy for a rather big xml schema. XmlSerializer is used to convert
object model to and from xml through XmlReader and XmlWriter. So, we get typed replacement
of generic XDocument that still supports the same LINQ API over collections of objects,
and takes less memory at runtime.
&lt;/p&gt;
&lt;p&gt;
The next step would be to commit a simple test like: 
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
read object model;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
transform it;
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
write it back.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
We have created such tests both for XDocument and for object model cases, and compared
results from different perspectives.
&lt;/p&gt;
&lt;p&gt;
Both solution produce very similar code, which is also similar to original xslt both
in style and size.
&lt;/p&gt;
&lt;p&gt;
Object model has static typing, which is much better to support.
&lt;/p&gt;
&lt;p&gt;
But the most unexpected outcome is that object model was up to 20% slower due to serialization
and deserialization even with pregenerated xmlserializer assemblies. Difference of
transformation performance and memory consumption was so unnoticable that it can be
neglected. These results were confirmed with multiple tests, with multiple cycles
including heating up cycles.
&lt;/p&gt;
&lt;p&gt;
Here we run into a case where static typing harms more than helps. Because of the
nature of our processing pipeline, which is offline batch, this difference can be
mapped into 10th of minutes or even more.
&lt;/p&gt;
&lt;p&gt;
Thus in this particular case we decided to stay with runtime typing as a more performant
way of processing in C#. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=486afbcd-3e16-4240-97c4-3c985d6c6754" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,486afbcd-3e16-4240-97c4-3c985d6c6754.aspx</comments>
      <category>.NET</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=fdbaf9f5-827b-4a1f-9e52-4ec569801784</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fdbaf9f5-827b-4a1f-9e52-4ec569801784</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Xslt is oftentimes thought as a tool to take input xml, and run transformation to
get html or some xml on output. Our use case is more complex, and is closer to a data
mining of big data in batch. Our transformation pipelines often take hour or more
to run even with SSD disks and with CPU cores fully loaded with work.
</p>
        <p>
So, we're looking for performance opportunities, and xml vs json might be promising.
</p>
        <p>
Here are our hypotheses:
</p>
        <ul>
          <li>
json is lighter than xml to serialize and deserialize;</li>
          <li>
json stored as map(*), array(*) and other items() are ligher than node() at runtime,
in particular subtree copy is zero cost in json;</li>
          <li>
templates with match patterns are efficiently can be implemented with maps();</li>
          <li>
there is incremental way forward from use of xml to use of json.</li>
        </ul>
        <p>
If it pays off we might be switching xml format to json all over, even though it is
a development effort.
</p>
        <p>
But to proceed we need to commit an experiment to measure processing speed of xml
vs json in xslt.
</p>
        <p>
Now our task is to find an isolated small representative sample to prove or reject
our hypotheses. 
</p>
        <p>
Better to start off with some existing transformation, and change it from use of xml
to json. 
</p>
        <p>
The question is whether there is such a candidate.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fdbaf9f5-827b-4a1f-9e52-4ec569801784" />
      </body>
      <title>xml vs json</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2022/04/16/xmlVsJson.aspx</link>
      <pubDate>Sat, 16 Apr 2022 19:03:04 GMT</pubDate>
      <description>&lt;p&gt;
Xslt is oftentimes thought as a tool to take input xml, and run transformation to
get html or some xml on output. Our use case is more complex, and is closer to a data
mining of big data in batch. Our transformation pipelines often take hour or more
to run even with SSD disks and with CPU cores fully loaded with work.
&lt;/p&gt;
&lt;p&gt;
So, we&amp;#39;re looking for performance opportunities, and xml vs json might be promising.
&lt;/p&gt;
&lt;p&gt;
Here are our hypotheses:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
json is lighter than xml to serialize and deserialize;&lt;/li&gt;
&lt;li&gt;
json stored as map(*), array(*) and other items() are ligher than node() at runtime,
in particular subtree copy is zero cost in json;&lt;/li&gt;
&lt;li&gt;
templates with match patterns are efficiently can be implemented with maps();&lt;/li&gt;
&lt;li&gt;
there is incremental way forward from use of xml to use of json.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
If it pays off we might be switching xml format to json all over, even though it is
a development effort.
&lt;/p&gt;
&lt;p&gt;
But to proceed we need to commit an experiment to measure processing speed of xml
vs json in xslt.
&lt;/p&gt;
&lt;p&gt;
Now our task is to find an isolated small representative sample to prove or reject
our hypotheses. 
&lt;/p&gt;
&lt;p&gt;
Better to start off with some existing transformation, and change it from use of xml
to json. 
&lt;/p&gt;
&lt;p&gt;
The question is whether there is such a candidate.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fdbaf9f5-827b-4a1f-9e52-4ec569801784" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fdbaf9f5-827b-4a1f-9e52-4ec569801784.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not sure what is use of our <a href="https://github.com/nesterovsky-bros/xslt-graph">Xslt
Graph exercises</a> but what we are sure with is that it stresses different parts
of Saxon Xslt engine and helps to find and resolve different bugs.
</p>
        <p>
While implementing <a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/biconnected-components.xslt">biconnected
components algorithm</a> we incidently run into <a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/tests/saxon-10.1-internal-error.xslt">internal
error with Saxon 10.1</a> with rather simple xslt:
</p>
        <blockquote>
          <pre>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  exclude-result-prefixes="xs array"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first as item(), $second as item()) 
        {  
          min(($first, $second))
        }
      )"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
More detail can be found at Saxon's issue tracker: <a href="https://saxonica.plan.io/issues/4578">Bug
#4578: NullPointerException when array:fold-left|right $zero argument is an empty
sequence</a>. 
</p>
        <p>
Bug is promptly resolved.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba" />
      </body>
      <title>Xslt Graph and Saxon processor</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/06/08/XsltGraphAndSaxonProcessor.aspx</link>
      <pubDate>Mon, 08 Jun 2020 05:58:32 GMT</pubDate>
      <description>&lt;p&gt;
Not sure what is use of our &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Xslt
Graph exercises&lt;/a&gt; but what we are sure with is that it stresses different parts
of Saxon Xslt engine and helps to find and resolve different bugs.
&lt;/p&gt;
&lt;p&gt;
While implementing &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/biconnected-components.xslt"&gt;biconnected
components algorithm&lt;/a&gt; we incidently run into &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/blob/master/tests/saxon-10.1-internal-error.xslt"&gt;internal
error with Saxon 10.1&lt;/a&gt; with rather simple xslt:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;?xml version="1.0" encoding="utf-8"?&gt;
&amp;lt;xsl:stylesheet version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:array="http://www.w3.org/2005/xpath-functions/array"
  exclude-result-prefixes="xs array"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:sequence select="
      array:fold-left
      (
        [8, 9], 
        (), 
        function($first as item(), $second as item()) 
        {  
          min(($first, $second))
        }
      )"/&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
More detail can be found at Saxon's issue tracker: &lt;a href="https://saxonica.plan.io/issues/4578"&gt;Bug
#4578: NullPointerException when array:fold-left|right $zero argument is an empty
sequence&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
Bug is promptly resolved.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=4196bfb4-24a3-4d7d-bea9-59bc907ce4ba" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,4196bfb4-24a3-4d7d-bea9-59bc907ce4ba.aspx</comments>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=8a79cdd8-4d17-416b-a82c-6b597dd36728</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=8a79cdd8-4d17-416b-a82c-6b597dd36728</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
While working on algorithm to trace <a href="https://en.wikipedia.org/wiki/Biconnected_component">Biconnected
components</a> for <a href="https://github.com/nesterovsky-bros/xslt-graph">Graph
API in the XSLT</a>  we realized that we implemented it unconventionally.
</p>
        <h3>A pseudocode in <a href="https://en.wikipedia.org/wiki/Biconnected_component">Wikipedia</a> is:
</h3>
        <pre>GetArticulationPoints(i, d)
    visited[i] := true
    depth[i] := d
    low[i] := d
    childCount := 0
    isArticulation := false

    <b>for
each</b> ni <b>in</b> adj[i] <b>do</b><b>if</b> not visited[ni] <b>then</b> parent[ni]
:= i GetArticulationPoints(ni, d + 1) childCount := childCount + 1 <b>if</b> low[ni]
≥ depth[i] <b>then</b> isArticulation := true low[i] := Min (low[i], low[ni]) <b>else
if</b> ni ≠ parent[i] <b>then</b> low[i] := Min (low[i], depth[ni]) <b>if</b> (parent[i]
≠ <b>null</b><b>and</b> isArticulation) <b>or</b> (parent[i] = <b>null</b><b>and</b> childCount
&gt; 1) <b>then</b> Output i as articulation point</pre>
        <p>
That algorithm is based on the fact that connected graph can be represented as a tree
of biconnected components. Vertices of such <b>tree</b> are called articulation points.
Implementation deals with a depth of each vertex, and with a lowpoint parameter that
is also related to vertex depth during Depth-First-Search.
</p>
        <p>
Out of interest we approached to the problem from different perspective. A vertex
is an articulation point if it has neighbors that cannot be combined into a path not
containing this vertex. As well as classical algorithm we use Depth-First-Search to
navigate the graph, but in contrast we collect cycles that pass through each vertex.
If during back pass of Depth-First-Search we find not cycle from "child"
to "ancestor" then it is necessary an articulation point.
</p>
        <h3>Here is pseudocode:
</h3>
        <pre>GetArticulationPoints(v, p) -&gt; result
    index = index + 1
    visited[v] = index 
    result = index
    articulation = p = null ? -1 : 0

    <b>for
each</b> n <b>in</b> neighbors of v <b>except</b> p <b>do</b><b>if</b> visited[n]
= 0 <b>then</b> nresult = GetArticulationPoints(n, v) result = min(result, nresult) <b>if</b> nresult
&gt;= visited[v] <b>then</b> articulation = articulation + 1 <b>else</b> result =
min(result, visited[n]) <b>if</b> articulation &gt; 0 <b>then</b> Output v as articulation
point</pre>
        <p>
Algorithms' complexity are the same.
</p>
        <p>
What is interesting is that we see no obvious way to transform one algorithm into
the other except from starting from Graph theory.
</p>
        <p>
More is on <a href="https://github.com/nesterovsky-bros/xslt-graph/wiki/Algorithm-for-Biconnected-components">Wiki</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8a79cdd8-4d17-416b-a82c-6b597dd36728" />
      </body>
      <title>Algorithm for Biconnected components</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/24/AlgorithmForBiconnectedComponents.aspx</link>
      <pubDate>Sun, 24 May 2020 12:15:02 GMT</pubDate>
      <description>  &lt;p&gt;
While working on algorithm to trace &lt;a href="https://en.wikipedia.org/wiki/Biconnected_component"&gt;Biconnected
components&lt;/a&gt; for &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Graph
API in the XSLT&lt;/a&gt;&amp;nbsp; we realized that we implemented it unconventionally.
&lt;/p&gt;
&lt;h3&gt;A pseudocode in &lt;a href="https://en.wikipedia.org/wiki/Biconnected_component"&gt;Wikipedia&lt;/a&gt; is:
&lt;/h3&gt;
&lt;pre&gt;GetArticulationPoints(i, d)
    visited[i] := true
    depth[i] := d
    low[i] := d
    childCount := 0
    isArticulation := false

    &lt;b&gt;for
each&lt;/b&gt; ni &lt;b&gt;in&lt;/b&gt; adj[i] &lt;b&gt;do&lt;/b&gt; &lt;b&gt;if&lt;/b&gt; not visited[ni] &lt;b&gt;then&lt;/b&gt; parent[ni]
:= i GetArticulationPoints(ni, d + 1) childCount := childCount + 1 &lt;b&gt;if&lt;/b&gt; low[ni]
≥ depth[i] &lt;b&gt;then&lt;/b&gt; isArticulation := true low[i] := Min (low[i], low[ni]) &lt;b&gt;else
if&lt;/b&gt; ni ≠ parent[i] &lt;b&gt;then&lt;/b&gt; low[i] := Min (low[i], depth[ni]) &lt;b&gt;if&lt;/b&gt; (parent[i]
≠ &lt;b&gt;null&lt;/b&gt; &lt;b&gt;and&lt;/b&gt; isArticulation) &lt;b&gt;or&lt;/b&gt; (parent[i] = &lt;b&gt;null&lt;/b&gt; &lt;b&gt;and&lt;/b&gt; childCount
&amp;gt; 1) &lt;b&gt;then&lt;/b&gt; Output i as articulation point&lt;/pre&gt;
&lt;p&gt;
That algorithm is based on the fact that connected graph can be represented as a tree
of biconnected components. Vertices of such &lt;b&gt;tree&lt;/b&gt; are called articulation points.
Implementation deals with a depth of each vertex, and with a lowpoint parameter that
is also related to vertex depth during Depth-First-Search.
&lt;/p&gt;
&lt;p&gt;
Out of interest we approached to the problem from different perspective. A vertex
is an articulation point if it has neighbors that cannot be combined into a path not
containing this vertex. As well as classical algorithm we use Depth-First-Search to
navigate the graph, but in contrast we collect cycles that pass through each vertex.
If during back pass of Depth-First-Search we find not cycle from &amp;quot;child&amp;quot;
to &amp;quot;ancestor&amp;quot; then it is necessary an articulation point.
&lt;/p&gt;
&lt;h3&gt;Here is pseudocode:
&lt;/h3&gt;
&lt;pre&gt;GetArticulationPoints(v, p) -&amp;gt; result
    index = index + 1
    visited[v] = index 
    result = index
    articulation = p = null ? -1 : 0

    &lt;b&gt;for
each&lt;/b&gt; n &lt;b&gt;in&lt;/b&gt; neighbors of v &lt;b&gt;except&lt;/b&gt; p &lt;b&gt;do&lt;/b&gt; &lt;b&gt;if&lt;/b&gt; visited[n]
= 0 &lt;b&gt;then&lt;/b&gt; nresult = GetArticulationPoints(n, v) result = min(result, nresult) &lt;b&gt;if&lt;/b&gt; nresult
&amp;gt;= visited[v] &lt;b&gt;then&lt;/b&gt; articulation = articulation + 1 &lt;b&gt;else&lt;/b&gt; result =
min(result, visited[n]) &lt;b&gt;if&lt;/b&gt; articulation &amp;gt; 0 &lt;b&gt;then&lt;/b&gt; Output v as articulation
point&lt;/pre&gt;
&lt;p&gt;
Algorithms&amp;#39; complexity are the same.
&lt;/p&gt;
&lt;p&gt;
What is interesting is that we see no obvious way to transform one algorithm into
the other except from starting from Graph theory.
&lt;/p&gt;
&lt;p&gt;
More is on &lt;a href="https://github.com/nesterovsky-bros/xslt-graph/wiki/Algorithm-for-Biconnected-components"&gt;Wiki&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=8a79cdd8-4d17-416b-a82c-6b597dd36728" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,8a79cdd8-4d17-416b-a82c-6b597dd36728.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c7ab748a-9b08-425c-83be-907ab4b7fef3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c7ab748a-9b08-425c-83be-907ab4b7fef3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Michael Key's <a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf">"A
Proposal for XSLT 4.0"</a> has spinned our interest in what could be added or
changed in XSLT. This way we decided to implement <a href="https://github.com/nesterovsky-bros/xslt-graph">Graph
API purely in xslt</a>. Our goal was to prove that:
</p>
        <ul>
          <li>
it's possible to provide efficient implementation of different Graph Algorithms in
XSLT;</li>
          <li>
to build Graph API the way that engine could provide native implementations of Grahp
Algorithms.</li>
          <li>
to find through an experiments what could be added to XSLT as a language.</li>
        </ul>
        <p>
At present we may confirm that first <a href="https://github.com/nesterovsky-bros/xslt-graph">two
goals are reachable</a>; and experiments have shown that XSLT could provide more help
to make program better, e.g. we have seen that language could simplify coding cycles.
</p>
        <p>
Graph algorithms are often expressed with while cycles, e.g <a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm">"Dijkstra's
algorithm"</a> has:
</p>
        <pre>12      while Q is not empty:
13          u ← vertex in Q with min dist[u]  
</pre>
        <p>
body is executed when condition is satisfied, but condition is impacted by body itself.
</p>
        <p>
In xslt 3.0 we did this with simple recursion:
</p>
        <pre>
&lt;xsl:template name="f:while" as="item()*"&gt;
  &lt;xsl:param name="condition" as="function(item()*) as xs:boolean"/&gt;
  &lt;xsl:param name="action" as="function(item()*) as item()*"/&gt;
  &lt;xsl:param name="next" as="function(item()*, item()*) as item()*"/&gt;
  &lt;xsl:param name="state" as="item()*"/&gt;

  &lt;xsl:if test="$condition($state)"&gt;
    &lt;xsl:variable name="items" as="item()*" select="$action($state)"/&gt;

    &lt;xsl:sequence select="$items"/&gt;

    &lt;xsl:call-template name="f:while"&gt;
      &lt;xsl:with-param name="condition" select="$condition"/&gt;
      &lt;xsl:with-param name="action" select="$action"/&gt;
      &lt;xsl:with-param name="next" select="$next"/&gt;
      &lt;xsl:with-param name="state" select="$next($state, $items)"/&gt;
    &lt;/xsl:call-template&gt;
  &lt;/xsl:if&gt;
&lt;/xsl:template&gt;
</pre>
        <p>
But here is the point. It could be done in more comprehended way. E.g. to let <code>xsl:iterate</code> without <code>select</code> to
cycle until <code>xsl:break</code> is reached.
</p>
        <pre>&lt;xsl:iterate&gt;
  &lt;xsl:param name="name" as="..." value="..."/&gt;
  
  &lt;xsl:if test="..."&gt;
    &lt;xsl:break/&gt;
  &lt;/xsl:if&gt;

  ...
&lt;/xsl:iterate&gt;</pre>
        <p>
So, what we propose is to let <code>xsl:iterate/@select</code> to be optional, and
change the behavior of processor when the attribute is missing from compilation error
to a valid behavior. This should not impact on any existing valid XSLT 3.0 program. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c7ab748a-9b08-425c-83be-907ab4b7fef3" />
      </body>
      <title>On XSLT 4</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/19/OnXSLT4.aspx</link>
      <pubDate>Tue, 19 May 2020 07:00:25 GMT</pubDate>
      <description>&lt;p&gt;
Michael Key&amp;#39;s &lt;a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf"&gt;&amp;quot;A
Proposal for XSLT 4.0&amp;quot;&lt;/a&gt; has spinned our interest in what could be added or
changed in XSLT. This way we decided to implement &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;Graph
API purely in xslt&lt;/a&gt;. Our goal was to prove that:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
it's possible to provide efficient implementation of different Graph Algorithms in
XSLT;&lt;/li&gt;
&lt;li&gt;
to build Graph API the way that engine could provide native implementations of Grahp
Algorithms.&lt;/li&gt;
&lt;li&gt;
to find through an experiments what could be added to XSLT as a language.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
At present we may confirm that first &lt;a href="https://github.com/nesterovsky-bros/xslt-graph"&gt;two
goals are reachable&lt;/a&gt;; and experiments have shown that XSLT could provide more help
to make program better, e.g. we have seen that language could simplify coding cycles.
&lt;/p&gt;
&lt;p&gt;
Graph algorithms are often expressed with while cycles, e.g &lt;a href="https://en.wikipedia.org/wiki/Dijkstra%27s_algorithm"&gt;&amp;quot;Dijkstra&amp;#39;s
algorithm&amp;quot;&lt;/a&gt; has:
&lt;/p&gt;
&lt;pre&gt;12      while Q is not empty:
13          u ← vertex in Q with min dist[u]  
&lt;/pre&gt;
&lt;p&gt;
body is executed when condition is satisfied, but condition is impacted by body itself.
&lt;/p&gt;
&lt;p&gt;
In xslt 3.0 we did this with simple recursion:
&lt;/p&gt;
&lt;pre&gt;
&amp;lt;xsl:template name="f:while" as="item()*"&gt;
  &amp;lt;xsl:param name="condition" as="function(item()*) as xs:boolean"/&gt;
  &amp;lt;xsl:param name="action" as="function(item()*) as item()*"/&gt;
  &amp;lt;xsl:param name="next" as="function(item()*, item()*) as item()*"/&gt;
  &amp;lt;xsl:param name="state" as="item()*"/&gt;

  &amp;lt;xsl:if test="$condition($state)"&gt;
    &amp;lt;xsl:variable name="items" as="item()*" select="$action($state)"/&gt;

    &amp;lt;xsl:sequence select="$items"/&gt;

    &amp;lt;xsl:call-template name="f:while"&gt;
      &amp;lt;xsl:with-param name="condition" select="$condition"/&gt;
      &amp;lt;xsl:with-param name="action" select="$action"/&gt;
      &amp;lt;xsl:with-param name="next" select="$next"/&gt;
      &amp;lt;xsl:with-param name="state" select="$next($state, $items)"/&gt;
    &amp;lt;/xsl:call-template&gt;
  &amp;lt;/xsl:if&gt;
&amp;lt;/xsl:template&gt;
&lt;/pre&gt;
&lt;p&gt;
But here is the point. It could be done in more comprehended way. E.g. to let &lt;code&gt;xsl:iterate&lt;/code&gt; without &lt;code&gt;select&lt;/code&gt; to
cycle until &lt;code&gt;xsl:break&lt;/code&gt; is reached.
&lt;/p&gt;
&lt;pre&gt;&amp;lt;xsl:iterate&amp;gt;
  &amp;lt;xsl:param name=&amp;quot;name&amp;quot; as=&amp;quot;...&amp;quot; value=&amp;quot;...&amp;quot;/&amp;gt;
  
  &amp;lt;xsl:if test=&amp;quot;...&amp;quot;&amp;gt;
    &amp;lt;xsl:break/&amp;gt;
  &amp;lt;/xsl:if&amp;gt;

  ...
&amp;lt;/xsl:iterate&amp;gt;&lt;/pre&gt;
&lt;p&gt;
So, what we propose is to let &lt;code&gt;xsl:iterate/@select&lt;/code&gt; to be optional, and
change the behavior of processor when the attribute is missing from compilation error
to a valid behavior. This should not impact on any existing valid XSLT 3.0 program. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c7ab748a-9b08-425c-83be-907ab4b7fef3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c7ab748a-9b08-425c-83be-907ab4b7fef3.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=57573dd7-7ec0-47e3-891e-aa186277e0f2</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=57573dd7-7ec0-47e3-891e-aa186277e0f2</wfw:commentRss>
      <title>Graphs in XSLT</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2020/05/12/GraphsInXSLT.aspx</link>
      <pubDate>Tue, 12 May 2020 06:08:51 GMT</pubDate>
      <description>  &lt;p&gt;
Recently we've read an article &lt;a href="http://www.saxonica.com/papers/xmlprague-2020mhk.pdf"&gt;&amp;quot;A
Proposal for XSLT 4.0&amp;quot;&lt;/a&gt;, and thought it worth to suggest one more idea. We
have written a &lt;a href="https://saxonica.plan.io/boards/2/topics/7870"&gt;message&lt;/a&gt; to
Michael Kay, author of this proposal. Here it is: 
&lt;/p&gt;
&lt;blockquote style="font-style: italic"&gt; &lt;b&gt;A&amp;V&lt;/b&gt; 
&lt;p&gt;
Historically xslt, xquery and xpath were dealing with trees. Nowadays it became much
common to process graphs. Many tasks can be formulated in terms of graphs, and in
particular any task processing trees is also graph task. 
&lt;/p&gt;
&lt;p&gt;
I suggest to take a deeper look in this direction. 
&lt;/p&gt;
&lt;p&gt;
As an inspiration I may suggest to look at &lt;a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1709r2.pdf"&gt;&amp;quot;P1709R2:
Graph Library&amp;quot;&lt;/a&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;- the C++ proposal. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;Michael Kay&lt;/b&gt; 
&lt;p&gt;
I have for many years found it frustrating that XML is confined to hierarchic relationships
(things like IDREF and XLink are clumsy workarounds); also the fact that the arbitrary
division of data into &amp;quot;documents&amp;quot; plays such a decisive role: documents
should only exist in the serialized representation of the model, not in the model
itself. 
&lt;/p&gt;
&lt;p&gt;
I started my career working with the Codasyl-defined network data model. It&amp;#39;s
a fine and very flexible data model; its downfall was the (DOM-like) procedural navigation
language. So I&amp;#39;ve often wondered what one could do trying to re-invent the Codasyl
model in a more modern idiom, coupling it with an XPath-like declarative access language
extended to handle networks (graphs) rather than hierarchies. 
&lt;/p&gt;
&lt;p&gt;
I&amp;#39;ve no idea how close a reinventiion of Codasyl would be to some of the modern
graph data models; it would be interesting to see. The other interesting aspect of
this is whether you can make it work for schema-less data. 
&lt;/p&gt;
&lt;p&gt;
But I don&amp;#39;t think that would be an incremental evolution of XSLT; I think it would
be something completely new. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;A&amp;V&lt;/b&gt; 
&lt;p&gt;
I was not so radical in my thoughts. &lt;img alt=":-)" src="http://www.nesterovsky-bros.com/weblog/smilies/happy.gif"&gt; 
&lt;/p&gt;
&lt;p&gt;
Even C++ API is not so radical, as they do not impose hard requirements on internal
graph representation but rather define template API that will work both with third
party representations (they even mention Fortran) or several built-in implementations
that uses standard vectors. 
&lt;/p&gt;
&lt;p&gt;
Their strong point is in algorithms provided as part of library and not graph internal
structure (I think authors of that paper have structured it not the best way). E.g.
in the second part they list graph algorithms: Depth First Search (DFS); Breadth First
Search (BFS); Topological Sort (TopoSort); Shortest Paths Algorithms; Dijkstra Algorithms;
and so on. 
&lt;/p&gt;
&lt;p&gt;
If we shall try to map it to xpath world them graph on API level might be represented
as a user function or as a map of user functions. 
&lt;/p&gt;
&lt;p&gt;
On a storage level user may implement graph using a sequence of maps or map of maps,
or even using xdm elements. 
&lt;/p&gt;
&lt;p&gt;
So, my approach is evolutional. In fact I suggest pure API that could even be implemented
now. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;Michael Kay&lt;/b&gt; 
&lt;p&gt;
Yes, there&amp;#39;s certainly scope for graph-oriented functions such as &lt;code&gt;closure($origin,
$function)&lt;/code&gt; and &lt;code&gt;is-reachable($origin, $function)&lt;/code&gt; and &lt;code&gt;find-path($origin,
$destination, $function)&lt;/code&gt; where we use the existing data model, treating any
item as a node in a graph, and representing the arcs using functions. There are a
few complications, e.g. what&amp;#39;s the identity comparison between arbitrary items,
but it can probably be done. 
&lt;/p&gt;
&lt;br /&gt;
&lt;b&gt;A&amp;V&lt;/b&gt; &lt;blockquote&gt; &gt; There are a few complications, e.g. what&amp;#39;s the identity
comparison between arbitrary items, but it can probably be done. &lt;/blockquote&gt; 
&lt;p&gt;
One approach to address this is through definition of graph API. E.g. to define graph
as a map (interface analogy) of functions, with equality functions, if required: 
&lt;/p&gt;
&lt;pre&gt;map
{
  vertices: function(),
  edges: function(),
  value: function(vertex),
  in-vertex: function(edge),
  out-vertex: function(edge),
  edges: function(vertex),
  is-in-vertex: function(edge, vertex),
  is-out-vertex: function(edge, vertex)
  ...
}&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Not sure how far this will go but who knows. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=57573dd7-7ec0-47e3-891e-aa186277e0f2" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,57573dd7-7ec0-47e3-891e-aa186277e0f2.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=6b76a0f7-4eee-4023-8f67-781c38550685</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=6b76a0f7-4eee-4023-8f67-781c38550685</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This story started half year ago when Michael Kay, author of Saxon XSLT processor,
was dealing with performance in multithreaded environment. See <a href="https://saxonica.plan.io/issues/3958">Bug
#3958</a>.
</p>
        <p>
The problem is like this.
</p>
        <p>
Given XSLT:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet exclude-result-prefixes="#all" 
  version="3.0" 
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &lt;xsl:output method="text" /&gt;

  &lt;xsl:template name="main"&gt;
    &lt;xsl:for-each saxon:threads="4" select="1 to 10"&gt;
      &lt;xsl:choose&gt;
        &lt;xsl:when test=". eq 1"&gt;
          &lt;!-- Will take 10 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/10')?url"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test=". eq 5"&gt;
          &lt;!-- Will take 9 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/9')?url"/&gt;
        &lt;/xsl:when&gt;
        &lt;xsl:when test=". eq 10"&gt;
          &lt;!-- Will take 8 seconds --&gt;
          &lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/8')?url"/&gt;
        &lt;/xsl:when&gt;
      &lt;/xsl:choose&gt;
    &lt;/xsl:for-each&gt;
    &lt;xsl:text&gt;
&lt;/xsl:text&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
Implement engine to achieve best performance of parallel for-each. 
</p>
        <p>
Naive implementation that will distribute iterations per threads will run into unfair
load on threads, so some load-balancing is required. That was the case Saxon EE. 
</p>
        <p>
Michael Kay has been trying to find most elegant way for the implementation and has
written the comment: 
</p>
        <blockquote>
          <i>I can't help feeling that the answer to this must lie in using the
Streams machinery, and Spliterators in particular. I've spent another hour or so reading
all about Spliterators, and I have to confess I really don't understand the paradigm.
If someone can enlighten me, please go ahead...</i>
        </blockquote>
        <p>
We have decided to take the challange and to model the expected behavior using Streams.
Here is our go: 
</p>
        <blockquote>
          <pre>import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.function.Consumer;
import java.util.function.Function;

public class Streams
{
  public static class Item&lt;T&gt;
  {
    public Item(int index, T data)
    {
      this.index = index;
      this.data = data;
    }
    
    int index;
    T data;
  }

  public static void main(String[] args)
  {
    run(
      "Sequential",
      input(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel ordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel unordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      false);    
  }
  
  private static void run(
    String description,
    Stream&lt;Item&lt;String&gt;&gt; input,
    Function&lt;Item&lt;String&gt;, String[]&gt; action,
    Consumer&lt;String[]&gt; output,
    boolean ordered)
  {
    System.out.println(description);
    
    long start = System.currentTimeMillis();
   
    if (ordered)
    {
      input.map(action).forEachOrdered(output);
    }
    else
    {
      input.map(action).forEach(output);
    }
    
    long end = System.currentTimeMillis();
    
    System.out.println("Execution time: " + (end - start) + "ms.");
    System.out.println();
  }
  
  private static Stream&lt;Item&lt;String&gt;&gt; input()
  {
    return IntStream.range(0, 10).
      mapToObj(i -&gt; new Item&lt;String&gt;(i + 1, "Data " + (i + 1)));
  }
  
  private static String[] action(Item&lt;String&gt; item)
  {
    switch(item.index)
    {
      case 1:
      {
        sleep(10);
        
        break;
      }
      case 5:
      {
        sleep(9);
        
        break;
      }
      case 10:
      {
        sleep(8);
        
        break;
      }
      default:
      {
        sleep(1);
        
        break;
      }
    }
    
    String[] result = { "data:", item.data, "index:", item.index + "" };
    
    return result;
  }
  
  private synchronized static void output(String[] value)
  {
    boolean first = true;
    
    for(String item: value)
    {
      if (first)
      {
        first = false;
      }
      else
      {
        System.out.print(' ');
      }
    
      System.out.print(item);
    }

    System.out.println();
  }
  
  private static void sleep(int seconds)
  {
    try
    {
      Thread.sleep(seconds * 1000);
    }
    catch(InterruptedException e)
    {
      throw new IllegalStateException(e);
    }
  }
}</pre>
        </blockquote>
        <p>
We model three cases:
</p>
        <dl>
          <dt>"Sequential"</dt>
          <dd>
slowest, single threaded execution with output: <pre>data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 34009ms.</pre></dd>
          <dt>"Parallel ordered"</dt>
          <dd>
fast, multithread execution preserving order, with output: <pre>data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 10019ms.</pre></dd>
          <dt>"Parallel unordered"</dt>
          <dd>
fastest, multithread execution not preserving order, with output: <pre>data: Data 6 index: 6
data: Data 2 index: 2
data: Data 4 index: 4
data: Data 3 index: 3
data: Data 9 index: 9
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 5 index: 5
data: Data 10 index: 10
data: Data 1 index: 1
Execution time: 10001ms.</pre></dd>
        </dl>
        <p>
What we can add in conclusion is that xslt engine could try automatically decide what
approach to use, as many SQL engines are doing, and not to force developer to go into
low level engine details.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6b76a0f7-4eee-4023-8f67-781c38550685" />
      </body>
      <title>Scheduling algorithm for xsl:for-each/@saxon:threads=N</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2019/03/24/SchedulingAlgorithmForXslforeachsaxonthreadsN.aspx</link>
      <pubDate>Sun, 24 Mar 2019 07:52:02 GMT</pubDate>
      <description>&lt;p&gt;
This story started half year ago when Michael Kay, author of Saxon XSLT processor,
was dealing with performance in multithreaded environment. See &lt;a href="https://saxonica.plan.io/issues/3958"&gt;Bug
#3958&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The problem is like this.
&lt;/p&gt;
&lt;p&gt;
Given XSLT:
&lt;/p&gt;
&lt;blockquote&gt; &lt;pre&gt;&amp;lt;xsl:stylesheet exclude-result-prefixes="#all" 
  version="3.0" 
  xmlns:saxon="http://saxon.sf.net/"
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;

  &amp;lt;xsl:output method="text" /&gt;

  &amp;lt;xsl:template name="main"&gt;
    &amp;lt;xsl:for-each saxon:threads="4" select="1 to 10"&gt;
      &amp;lt;xsl:choose&gt;
        &amp;lt;xsl:when test=". eq 1"&gt;
          &amp;lt;!-- Will take 10 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/10')?url"/&gt;
        &amp;lt;/xsl:when&gt;
        &amp;lt;xsl:when test=". eq 5"&gt;
          &amp;lt;!-- Will take 9 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/9')?url"/&gt;
        &amp;lt;/xsl:when&gt;
        &amp;lt;xsl:when test=". eq 10"&gt;
          &amp;lt;!-- Will take 8 seconds --&gt;
          &amp;lt;xsl:sequence select="
            json-doc('https://httpbin.org/delay/8')?url"/&gt;
        &amp;lt;/xsl:when&gt;
      &amp;lt;/xsl:choose&gt;
    &amp;lt;/xsl:for-each&gt;
    &amp;lt;xsl:text&gt;&amp;#x0A;&amp;lt;/xsl:text&gt;
  &amp;lt;/xsl:template&gt;
&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
Implement engine to achieve best performance of parallel for-each. 
&lt;/p&gt;
&lt;p&gt;
Naive implementation that will distribute iterations per threads will run into unfair
load on threads, so some load-balancing is required. That was the case Saxon EE. 
&lt;/p&gt;
&lt;p&gt;
Michael Kay has been trying to find most elegant way for the implementation and has
written the comment: 
&lt;/p&gt;
&lt;blockquote&gt; &lt;i&gt;I can't help feeling that the answer to this must lie in using the
Streams machinery, and Spliterators in particular. I've spent another hour or so reading
all about Spliterators, and I have to confess I really don't understand the paradigm.
If someone can enlighten me, please go ahead...&lt;/i&gt; &lt;/blockquote&gt; 
&lt;p&gt;
We have decided to take the challange and to model the expected behavior using Streams.
Here is our go: 
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;import java.util.stream.IntStream;
import java.util.stream.Stream;
import java.util.function.Consumer;
import java.util.function.Function;

public class Streams
{
  public static class Item&amp;lt;T&gt;
  {
    public Item(int index, T data)
    {
      this.index = index;
      this.data = data;
    }
    
    int index;
    T data;
  }

  public static void main(String[] args)
  {
    run(
      "Sequential",
      input(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel ordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      true);
    
    run(
      "Parallel unordered", 
      input().parallel(),
      Streams::action,
      Streams::output,
      false);    
  }
  
  private static void run(
    String description,
    Stream&amp;lt;Item&amp;lt;String&gt;&gt; input,
    Function&amp;lt;Item&amp;lt;String&gt;, String[]&gt; action,
    Consumer&amp;lt;String[]&gt; output,
    boolean ordered)
  {
    System.out.println(description);
    
    long start = System.currentTimeMillis();
   
    if (ordered)
    {
      input.map(action).forEachOrdered(output);
    }
    else
    {
      input.map(action).forEach(output);
    }
    
    long end = System.currentTimeMillis();
    
    System.out.println("Execution time: " + (end - start) + "ms.");
    System.out.println();
  }
  
  private static Stream&amp;lt;Item&amp;lt;String&gt;&gt; input()
  {
    return IntStream.range(0, 10).
      mapToObj(i -&gt; new Item&amp;lt;String&gt;(i + 1, "Data " + (i + 1)));
  }
  
  private static String[] action(Item&amp;lt;String&gt; item)
  {
    switch(item.index)
    {
      case 1:
      {
        sleep(10);
        
        break;
      }
      case 5:
      {
        sleep(9);
        
        break;
      }
      case 10:
      {
        sleep(8);
        
        break;
      }
      default:
      {
        sleep(1);
        
        break;
      }
    }
    
    String[] result = { "data:", item.data, "index:", item.index + "" };
    
    return result;
  }
  
  private synchronized static void output(String[] value)
  {
    boolean first = true;
    
    for(String item: value)
    {
      if (first)
      {
        first = false;
      }
      else
      {
        System.out.print(' ');
      }
    
      System.out.print(item);
    }

    System.out.println();
  }
  
  private static void sleep(int seconds)
  {
    try
    {
      Thread.sleep(seconds * 1000);
    }
    catch(InterruptedException e)
    {
      throw new IllegalStateException(e);
    }
  }
}&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We model three cases:
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;"Sequential"&lt;/dt&gt; 
&lt;dd&gt;
slowest, single threaded execution with output: &lt;pre&gt;data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 34009ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;"Parallel ordered"&lt;/dt&gt; 
&lt;dd&gt;
fast, multithread execution preserving order, with output: &lt;pre&gt;data: Data 1 index: 1
data: Data 2 index: 2
data: Data 3 index: 3
data: Data 4 index: 4
data: Data 5 index: 5
data: Data 6 index: 6
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 9 index: 9
data: Data 10 index: 10
Execution time: 10019ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;dt&gt;"Parallel unordered"&lt;/dt&gt; 
&lt;dd&gt;
fastest, multithread execution not preserving order, with output: &lt;pre&gt;data: Data 6 index: 6
data: Data 2 index: 2
data: Data 4 index: 4
data: Data 3 index: 3
data: Data 9 index: 9
data: Data 7 index: 7
data: Data 8 index: 8
data: Data 5 index: 5
data: Data 10 index: 10
data: Data 1 index: 1
Execution time: 10001ms.&lt;/pre&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;p&gt;
What we can add in conclusion is that xslt engine could try automatically decide what
approach to use, as many SQL engines are doing, and not to force developer to go into
low level engine details.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6b76a0f7-4eee-4023-8f67-781c38550685" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,6b76a0f7-4eee-4023-8f67-781c38550685.aspx</comments>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7916d7f6-9228-48f2-9b06-d2646328ec33</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7916d7f6-9228-48f2-9b06-d2646328ec33</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we observed how we solved the same task in different versions of XPath: 2.0,
3.0, and 3.1.
</p>
        <p>
Consider, you have a sequence <code>$items</code>, and you want to call some function
over each item of the sequence, and to return combined result.
</p>
        <p>
In XPath 2.0 this was solved like this:
</p>
        <blockquote>
          <pre>for $item in $items return
  f:func($item)</pre>
        </blockquote>
        <p>
In XPath 3.0 this was solved like this:
</p>
        <blockquote>
          <pre>$items!f:func(.)</pre>
        </blockquote>
        <p>
And now with XPath 3.1 that defined an arrow operator =&gt; we attempted to write something
as simple as:
</p>
        <blockquote>
          <pre>$items=&gt;f:func()</pre>
        </blockquote>
        <p>
That is definitely not working, as it is the same as <code>f:func($items)</code>.
</p>
        <p>
Next attempt was:
</p>
        <blockquote>
          <pre>$items!=&gt;f:func()</pre>
        </blockquote>
        <p>
That even does not compile.
</p>
        <p>
So, finally, working expression using =&gt; looks like this:
</p>
        <blockquote>
          <pre>$items!(.=&gt;f:func())</pre>
        </blockquote>
        <p>
This looks like a step back comparing to XPath 3.0 variant.
</p>
        <p>
More than that, XPath grammar of arrow operator forbids the use of predictes, axis
or mapping operators, so this won't compile:
</p>
        <blockquote>
          <pre>$items!(.=&gt;f:func()[1])</pre>
        </blockquote>
        <blockquote>
          <pre>$items!(.=&gt;f:func()!something)</pre>
        </blockquote>
        <p>
Our conclusion is that arrow operator is rather confusing addition to XPath.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7916d7f6-9228-48f2-9b06-d2646328ec33" />
      </body>
      <title>XPath through evolution</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/11/03/XPathThroughEvolution.aspx</link>
      <pubDate>Sat, 03 Nov 2018 20:59:28 GMT</pubDate>
      <description>  &lt;p&gt;
Recently we observed how we solved the same task in different versions of XPath: 2.0,
3.0, and 3.1.
&lt;/p&gt;
&lt;p&gt;
Consider, you have a sequence &lt;code&gt;$items&lt;/code&gt;, and you want to call some function
over each item of the sequence, and to return combined result.
&lt;/p&gt;
&lt;p&gt;
In XPath 2.0 this was solved like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;for $item in $items return
  f:func($item)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
In XPath 3.0 this was solved like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!f:func(.)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
And now with XPath 3.1 that defined an arrow operator =&gt; we attempted to write something
as simple as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items=&gt;f:func()&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
That is definitely not working, as it is the same as &lt;code&gt;f:func($items)&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Next attempt was:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!=&gt;f:func()&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
That even does not compile.
&lt;/p&gt;
&lt;p&gt;
So, finally, working expression using =&gt; looks like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func())&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This looks like a step back comparing to XPath 3.0 variant.
&lt;/p&gt;
&lt;p&gt;
More than that, XPath grammar of arrow operator forbids the use of predictes, axis
or mapping operators, so this won't compile:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func()[1])&lt;/pre&gt;&lt;/blockquote&gt; &lt;blockquote&gt;&lt;pre&gt;$items!(.=&gt;f:func()!something)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Our conclusion is that arrow operator is rather confusing addition to XPath.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7916d7f6-9228-48f2-9b06-d2646328ec33" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7916d7f6-9228-48f2-9b06-d2646328ec33.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=2b29772d-bded-4045-b6b8-d0035cb5944f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=2b29772d-bded-4045-b6b8-d0035cb5944f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Xslt 3.0 defines a feature called streamability: a technique to write xslt code that
is able to handle arbitrary sized inputs. 
</p>
        <p>
This contrasts with conventional xslt code (and xslt engines) where inputs are completely
loaded in memory.
</p>
        <p>
To make code streamable a developer should declare her code as such, and the code
should pass <a href="https://www.w3.org/TR/xslt-30/#streamability">Streamability analysis</a>.
</p>
        <p>
The goal is to define subset of xslt/xpath operations that allow to process input
in one pass.
</p>
        <p>
In simple case it's indeed a simple task to verify that code is streamable, but
the more complex your code is the less trivial it's to witness it is streamable.
</p>
        <p>
On the forums we have seen a lot of discussions, where experts were trying to figure
out whether particular xslt is streamable. At times it's remarkably untrivial
task!
</p>
        <p>
This, in our opinion, clearly manifests that the feature is largerly failed attempt
to inscribe some optimization technique into xslt spec.
</p>
        <p>
The place of such optimization is in the implementation space, and not in spec. Engine
had to attempt such optimization and fallback to the traditional implementation.
</p>
        <p>
The last such example is: <a href="https://saxonica.plan.io/boards/3/topics/7319">Getting
SXST0060 "No streamable path found in expression" when trying to push a
map with grounded nodes to a template of a streamable mode</a>, where both xslt code
and engine developers are not sure that the code is streamable in the first place.
</p>
        <p>
        </p>
        <p>
By the way, besides streamability there is other optimization technique that works
probably in all SQL engines. When data does not fit into memory engine may spill it
on disk. Thus trading memory pressure for disk access. So, why didn't such techninque
find the way into the Xslt or SQL specs?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2b29772d-bded-4045-b6b8-d0035cb5944f" />
      </body>
      <title>Xslt Streamability</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/10/02/XsltStreamability.aspx</link>
      <pubDate>Tue, 02 Oct 2018 12:50:22 GMT</pubDate>
      <description>  &lt;p&gt;
Xslt 3.0 defines a feature called streamability: a technique to write xslt code that
is able to handle arbitrary sized inputs. 
&lt;/p&gt;
&lt;p&gt;
This contrasts with conventional xslt code (and xslt engines) where inputs are completely
loaded in memory.
&lt;/p&gt;
&lt;p&gt;
To make code streamable a developer should declare her code as such, and the code
should pass &lt;a href="https://www.w3.org/TR/xslt-30/#streamability"&gt;Streamability analysis&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
The goal is to define subset of xslt/xpath operations that allow to process input
in one pass.
&lt;/p&gt;
&lt;p&gt;
In simple case it&amp;#39;s indeed a simple task to verify that code is streamable, but
the more complex your code is the less trivial it&amp;#39;s to witness it is streamable.
&lt;/p&gt;
&lt;p&gt;
On the forums we have seen a lot of discussions, where experts were trying to figure
out whether particular xslt is streamable. At times it&amp;#39;s remarkably untrivial
task!
&lt;/p&gt;
&lt;p&gt;
This, in our opinion, clearly manifests that the feature is largerly failed attempt
to inscribe some optimization technique into xslt spec.
&lt;/p&gt;
&lt;p&gt;
The place of such optimization is in the implementation space, and not in spec. Engine
had to attempt such optimization and fallback to the traditional implementation.
&lt;/p&gt;
&lt;p&gt;
The last such example is: &lt;a href="https://saxonica.plan.io/boards/3/topics/7319"&gt;Getting
SXST0060 &amp;quot;No streamable path found in expression&amp;quot; when trying to push a
map with grounded nodes to a template of a streamable mode&lt;/a&gt;, where both xslt code
and engine developers are not sure that the code is streamable in the first place.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
By the way, besides streamability there is other optimization technique that works
probably in all SQL engines. When data does not fit into memory engine may spill it
on disk. Thus trading memory pressure for disk access. So, why didn&amp;#39;t such techninque
find the way into the Xslt or SQL specs?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=2b29772d-bded-4045-b6b8-d0035cb5944f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,2b29772d-bded-4045-b6b8-d0035cb5944f.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ebe76efc-3ec2-463d-a666-3741bdebbf82</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ebe76efc-3ec2-463d-a666-3741bdebbf82</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Saxon 9.9.0-1 is out!
</p>
        <p>
Shortly we have reported our first bug in the new version. See <a href="https://saxonica.plan.io/issues/3923">https://saxonica.plan.io/issues/3923</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebe76efc-3ec2-463d-a666-3741bdebbf82" />
      </body>
      <title>Saxon 9.9.0-1 is out</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/28/Saxon9901IsOut.aspx</link>
      <pubDate>Fri, 28 Sep 2018 17:47:37 GMT</pubDate>
      <description>&lt;p&gt;
Saxon 9.9.0-1 is out!
&lt;/p&gt;
&lt;p&gt;
Shortly we have reported our first bug in the new version. See &lt;a href="https://saxonica.plan.io/issues/3923"&gt;https://saxonica.plan.io/issues/3923&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebe76efc-3ec2-463d-a666-3741bdebbf82" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebe76efc-3ec2-463d-a666-3741bdebbf82.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c54ee192-82aa-4912-a19a-e312b603016d</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c54ee192-82aa-4912-a19a-e312b603016d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After 17 years of experience we still run into dummy bugs in xslt (xpath in fact).
</p>
        <p>
The latest one is related to order of nodes produced by ancestor-or-self axis.
</p>
        <p>
Consider the code:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="data" as="element()"&gt;
      &lt;a&gt;
        &lt;b&gt;
          &lt;c/&gt;
        &lt;/b&gt;
      &lt;/a&gt;
    &lt;/xsl:variable&gt;

    &lt;xsl:variable name="item" as="element()" select="($data//c)[1]"/&gt;

    &lt;xsl:message select="$item!ancestor-or-self::*!local-name()"/&gt;
    &lt;xsl:message select="$item!local-name(), $item!..!local-name(), $item!..!..!local-name()"/&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
We expected to have the following outcome
</p>
        <ul>
          <li>
            <code>c b a</code>
          </li>
          <li>
            <code>c b a</code>
          </li>
        </ul>
        <p>
But correct one is
</p>
        <ul>
          <li>
            <code>a b c</code>
          </li>
          <li>
            <code>c b a</code>
          </li>
        </ul>
        <p>
Here is why:
</p>
        <blockquote>
          <i>
            <code>ancestor-or-self::*</code> is an AxisStep. From XPath §3.3.2:</i>
          <br />
          <br />
          <i>[Definition: An axis step returns a sequence of nodes that are reachable from the
context node via a specified axis. Such a step has two parts: an axis, which defines
the "direction of movement" for the step, and a node test, which selects
nodes based on their kind, name, and/or type annotation.] If the context item is a
node, an axis step returns a sequence of zero or more nodes; otherwise, a type error
is raised [err:XPTY0020]. <strong>The resulting node sequence is returned in document
order</strong>. </i>
        </blockquote>
        <p>
For some reason we were thinking that reverse axis produces result in reverse order.
It turns out the reverse order is only within predicate of such axis.
</p>
        <p>
See more at <a href="https://saxonica.plan.io/boards/3/topics/7312">https://saxonica.plan.io/boards/3/topics/7312</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c54ee192-82aa-4912-a19a-e312b603016d" />
      </body>
      <title>Fail with ancestor-or-self</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/27/FailWithAncestororself.aspx</link>
      <pubDate>Thu, 27 Sep 2018 05:52:58 GMT</pubDate>
      <description>&lt;p&gt;
After 17 years of experience we still run into dummy bugs in xslt (xpath in fact).
&lt;/p&gt;
&lt;p&gt;
The latest one is related to order of nodes produced by ancestor-or-self axis.
&lt;/p&gt;
&lt;p&gt;
Consider the code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="data" as="element()"&gt;
      &amp;lt;a&gt;
        &amp;lt;b&gt;
          &amp;lt;c/&gt;
        &amp;lt;/b&gt;
      &amp;lt;/a&gt;
    &amp;lt;/xsl:variable&gt;

    &amp;lt;xsl:variable name="item" as="element()" select="($data//c)[1]"/&gt;

    &amp;lt;xsl:message select="$item!ancestor-or-self::*!local-name()"/&gt;
    &amp;lt;xsl:message select="$item!local-name(), $item!..!local-name(), $item!..!..!local-name()"/&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We expected to have the following outcome
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
But correct one is
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;a b c&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;c b a&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Here is why:
&lt;/p&gt;
&lt;blockquote&gt; &lt;i&gt; &lt;code&gt;ancestor-or-self::*&lt;/code&gt; is an AxisStep. From XPath §3.3.2:&lt;/i&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;i&gt;[Definition: An axis step returns a sequence of nodes that are reachable from the
context node via a specified axis. Such a step has two parts: an axis, which defines
the &amp;quot;direction of movement&amp;quot; for the step, and a node test, which selects
nodes based on their kind, name, and/or type annotation.] If the context item is a
node, an axis step returns a sequence of zero or more nodes; otherwise, a type error
is raised [err:XPTY0020]. &lt;strong&gt;The resulting node sequence is returned in document
order&lt;/strong&gt;. &lt;/i&gt; &lt;/blockquote&gt; 
&lt;p&gt;
For some reason we were thinking that reverse axis produces result in reverse order.
It turns out the reverse order is only within predicate of such axis.
&lt;/p&gt;
&lt;p&gt;
See more at &lt;a href="https://saxonica.plan.io/boards/3/topics/7312"&gt;https://saxonica.plan.io/boards/3/topics/7312&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c54ee192-82aa-4912-a19a-e312b603016d" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c54ee192-82aa-4912-a19a-e312b603016d.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=278ad22c-a125-4dd1-a66e-1a7f1ba0b381</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=278ad22c-a125-4dd1-a66e-1a7f1ba0b381</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
XPath 3 has introduced a syntactic sugar for a string concatenation, so following:
</p>
        <blockquote>
          <pre>concat($a, $b)</pre>
        </blockquote>
        <p>
can be now written as:
</p>
        <blockquote>
          <pre>$a || $b</pre>
        </blockquote>
        <p>
This is nice addition, except when you run into a trouble. Being rooted in C world
we unintentionally have written a following xslt code:
</p>
        <blockquote>
          <pre>&lt;xsl:if test="$a || $b"&gt;
...
&lt;/xsl:if&gt;</pre>
        </blockquote>
        <p>
Clearly, we intended to write <code>$a or $b</code>. In contrast <code> $a || $b</code> is
evaluated as <code>concat($a, $b)</code>. If both variables are <code>false()</code> we
get <code>'falsefalse'</code> outcome, which has effective boolean value <code>true()</code>.
This means that test condition of <code>xsl:if</code> is always <code>true()</code>.
</p>
        <p>
        </p>
        <p>
What can be done to avoid such unfortunate typo, which is manifested in no way neither
during compilation nor during runtime?
</p>
        <p>
The answer is to issue informational message during the compilation, e.g. if result
of || operator is converted to a boolean, and if its arguments are booleans also then
chances are high this is typo, and not intentional expression.
</p>
        <p>
We adviced to implement such message in the saxon processor (see <a href="https://saxonica.plan.io/boards/3/topics/7305">https://saxonica.plan.io/boards/3/topics/7305</a>).
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=278ad22c-a125-4dd1-a66e-1a7f1ba0b381" />
      </body>
      <title>|| in boolean expression in XPath</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/18/InBooleanExpressionInXPath.aspx</link>
      <pubDate>Tue, 18 Sep 2018 12:23:08 GMT</pubDate>
      <description>  &lt;p&gt;
XPath 3 has introduced a syntactic sugar for a string concatenation, so following:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;concat($a, $b)&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
can be now written as:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;$a || $b&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This is nice addition, except when you run into a trouble. Being rooted in C world
we unintentionally have written a following xslt code:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:if test=&amp;quot;$a || $b&amp;quot;&amp;gt;
...
&amp;lt;/xsl:if&amp;gt;&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Clearly, we intended to write &lt;code&gt;$a or $b&lt;/code&gt;. In contrast &lt;code&gt; $a || $b&lt;/code&gt; is
evaluated as &lt;code&gt;concat($a, $b)&lt;/code&gt;. If both variables are &lt;code&gt;false()&lt;/code&gt; we
get &lt;code&gt;'falsefalse'&lt;/code&gt; outcome, which has effective boolean value &lt;code&gt;true()&lt;/code&gt;.
This means that test condition of &lt;code&gt;xsl:if&lt;/code&gt; is always &lt;code&gt;true()&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;p&gt;
What can be done to avoid such unfortunate typo, which is manifested in no way neither
during compilation nor during runtime?
&lt;/p&gt;
&lt;p&gt;
The answer is to issue informational message during the compilation, e.g. if result
of || operator is converted to a boolean, and if its arguments are booleans also then
chances are high this is typo, and not intentional expression.
&lt;/p&gt;
&lt;p&gt;
We adviced to implement such message in the saxon processor (see &lt;a href="https://saxonica.plan.io/boards/3/topics/7305"&gt;https://saxonica.plan.io/boards/3/topics/7305&lt;/a&gt;).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=278ad22c-a125-4dd1-a66e-1a7f1ba0b381" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,278ad22c-a125-4dd1-a66e-1a7f1ba0b381.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=07cc910c-dabb-4970-9a75-a87d36c9a50b</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=07cc910c-dabb-4970-9a75-a87d36c9a50b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It seems we've found discrepancy in regex implementation during the transformation
in Saxon. Consider the following xslt:
</p>
        <pre>&lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="text" as="xs:string" 
      select="'A = &amp;quot;a&amp;quot; OR B = &amp;quot;b&amp;quot;'"/&gt;

    &lt;xsl:analyze-string regex="&amp;quot;(\\&amp;quot;|.)*?&amp;quot;" select="$text"&gt;
      &lt;xsl:matching-substring&gt;
        &lt;xsl:message&gt;
          &lt;xsl:sequence select="regex-group(0)"/&gt;
        &lt;/xsl:message&gt;
      &lt;/xsl:matching-substring&gt;
    &lt;/xsl:analyze-string&gt;
  &lt;/xsl:template&gt;

&lt;/xsl:stylesheet&gt;</pre>
vs javascript <pre>&lt;html&gt;
&lt;body&gt;
  &lt;script&gt;
    var text = 'A = "a" OR B = "b"';
    var regex = /"(\\"|.)*?"/;
    var match = text.match(regex);

    alert(match[0]);
  &lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre><p>
xslt produces: "a" OR B = "b"
</p><p>
while javascript: "a"
</p><p>
What is interesting is that we're certain this was working correctly in Saxon several
years ago. 
</p><p>
You can track progress of the bug at: <a href="https://saxonica.plan.io/boards/3/topics/7300">https://saxonica.plan.io/boards/3/topics/7300</a> and
at <a href="https://saxonica.plan.io/issues/3902">https://saxonica.plan.io/issues/3902</a>.
</p><img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=07cc910c-dabb-4970-9a75-a87d36c9a50b" /></body>
      <title>Bug with regex in Saxon xslt</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2018/09/13/BugWithRegexInSaxonXslt.aspx</link>
      <pubDate>Thu, 13 Sep 2018 06:29:05 GMT</pubDate>
      <description>&lt;p&gt;
It seems we've found discrepancy in regex implementation during the transformation
in Saxon. Consider the following xslt:
&lt;/p&gt;
&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0" 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="text" as="xs:string" 
      select="'A = &amp;amp;quot;a&amp;amp;quot; OR B = &amp;amp;quot;b&amp;amp;quot;'"/&gt;

    &amp;lt;xsl:analyze-string regex="&amp;amp;quot;(\\&amp;amp;quot;|.)*?&amp;amp;quot;" select="$text"&gt;
      &amp;lt;xsl:matching-substring&gt;
        &amp;lt;xsl:message&gt;
          &amp;lt;xsl:sequence select="regex-group(0)"/&gt;
        &amp;lt;/xsl:message&gt;
      &amp;lt;/xsl:matching-substring&gt;
    &amp;lt;/xsl:analyze-string&gt;
  &amp;lt;/xsl:template&gt;

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
vs javascript &lt;pre&gt;&amp;lt;html&gt;
&amp;lt;body&gt;
  &amp;lt;script&gt;
    var text = 'A = "a" OR B = "b"';
    var regex = /"(\\"|.)*?"/;
    var match = text.match(regex);

    alert(match[0]);
  &amp;lt;/script&gt;
&amp;lt;/body&gt;
&amp;lt;/html&gt;&lt;/pre&gt;
&lt;p&gt;
xslt produces: "a" OR B = "b"
&lt;/p&gt;
&lt;p&gt;
while javascript: "a"
&lt;/p&gt;
&lt;p&gt;
What is interesting is that we're certain this was working correctly in Saxon several
years ago. 
&lt;/p&gt;
&lt;p&gt;
You can track progress of the bug at: &lt;a href="https://saxonica.plan.io/boards/3/topics/7300"&gt;https://saxonica.plan.io/boards/3/topics/7300&lt;/a&gt; and
at &lt;a href="https://saxonica.plan.io/issues/3902"&gt;https://saxonica.plan.io/issues/3902&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=07cc910c-dabb-4970-9a75-a87d36c9a50b" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,07cc910c-dabb-4970-9a75-a87d36c9a50b.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7a16adad-f987-4c87-909e-3bcc856c58a6</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7a16adad-f987-4c87-909e-3bcc856c58a6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We've found that there is a Saxon HE update that was going to fix problems we mentioned
in the previous post, and decided to give it a second chance.
</p>
        <p>
Now Saxon fails with two other errors:
</p>
        <ul>
          <li>
            <a href="https://saxonica.plan.io/boards/3/topics/6838">Bad parent pointer message
in Saxon-HE-9.8.0-2</a>
          </li>
          <li>
            <a href="https://saxonica.plan.io/boards/3/topics/6839">XTDE1061: There is no current
group in Saxon-HE-9.8.0-2</a>
          </li>
        </ul>
        <p>
We shall be waiting for the fixes. Mean time we're back to version 9.7.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7a16adad-f987-4c87-909e-3bcc856c58a6" />
      </body>
      <title>Saxon 9.8.0-2 second attempt.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/06/27/Saxon9802SecondAttempt.aspx</link>
      <pubDate>Tue, 27 Jun 2017 22:30:28 GMT</pubDate>
      <description>&lt;p&gt;
We've found that there is a Saxon HE update that was going to fix problems we mentioned
in the previous post, and decided to give it a second chance.
&lt;/p&gt;
&lt;p&gt;
Now Saxon fails with two other errors:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://saxonica.plan.io/boards/3/topics/6838"&gt;Bad parent pointer message
in Saxon-HE-9.8.0-2&lt;/a&gt; 
&lt;li&gt;
&lt;a href="https://saxonica.plan.io/boards/3/topics/6839"&gt;XTDE1061: There is no current
group in Saxon-HE-9.8.0-2&lt;/a&gt; 
&lt;/ul&gt;
&lt;p&gt;
We shall be waiting for the fixes. Mean time we're back to version 9.7.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7a16adad-f987-4c87-909e-3bcc856c58a6" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7a16adad-f987-4c87-909e-3bcc856c58a6.aspx</comments>
      <category>Announce</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=af6dddad-e60e-4f56-83b2-e9f3fce700fd</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=af6dddad-e60e-4f56-83b2-e9f3fce700fd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Finally, Saxon 9.8 is out!<br />
This means that basic xslt 3 is available in the HE version.<br /><br />
Update: as usually, each new release has new bugs...<br />
See https://saxonica.plan.io/boards/3/topics/6809<img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=af6dddad-e60e-4f56-83b2-e9f3fce700fd" /></body>
      <title>Saxon 9.8 is out</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/06/14/Saxon98IsOut.aspx</link>
      <pubDate>Wed, 14 Jun 2017 21:05:51 GMT</pubDate>
      <description>Finally, Saxon 9.8 is out!&lt;br /&gt;
This means that basic xslt 3 is available in the HE version.&lt;br&gt;
&lt;br&gt;
Update: as usually, each new release has new bugs...&lt;br&gt;
See https://saxonica.plan.io/boards/3/topics/6809&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=af6dddad-e60e-4f56-83b2-e9f3fce700fd" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,af6dddad-e60e-4f56-83b2-e9f3fce700fd.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=824d5dcd-a1a5-4314-b7fa-1e4447417c9f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=824d5dcd-a1a5-4314-b7fa-1e4447417c9f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have found that Saxon HE 9.7.0-18 has finally exposed partial support to map and
array item types. So, now you can encapsulate your data in sequence rather than having
a single sequence and treating odd and even elements specially.
</p>
        <p>
Basic example is:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:t="t"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  exclude-result-prefixes="xs t map"&gt;

  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="map" as="map(xs:string, xs:string)" select="
      map 
      {
        'Su': 'Sunday',
        'Mo': 'Monday',
        'Tu': 'Tuesday',
        'We': 'Wednesday',
        'Th': 'Thursday',
        'Fr': 'Friday',
        'Sa': 'Saturday'
      }"/&gt;
      
     &lt;xsl:message select="map:keys($map)"/&gt;
  &lt;/xsl:template&gt;  

&lt;/xsl:stylesheet&gt;</pre>
        </blockquote>
        <p>
A list of map functions can be found here <a href="http://www.w3.org/2005/xpath-functions/map/">http://www.w3.org/2005/xpath-functions/map/</a>,
though not all are available, as Saxon HE still does not allow inline functions.
</p>
        <p>
P.S. From the development perspective it's a great harm that Saxon HE is so limited.
Basically limited to xslt 2.0 + some selected parts of 3.0.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=824d5dcd-a1a5-4314-b7fa-1e4447417c9f" />
      </body>
      <title>Saxon HE map and array types.</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/05/16/SaxonHEMapAndArrayTypes.aspx</link>
      <pubDate>Tue, 16 May 2017 06:20:48 GMT</pubDate>
      <description>  &lt;p&gt;
We have found that Saxon HE 9.7.0-18 has finally exposed partial support to map and
array item types. So, now you can encapsulate your data in sequence rather than having
a single sequence and treating odd and even elements specially.
&lt;/p&gt;
&lt;p&gt;
Basic example is:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:t="t"
  xmlns:map="http://www.w3.org/2005/xpath-functions/map"
  exclude-result-prefixes="xs t map"&gt;

  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="map" as="map(xs:string, xs:string)" select="
      map 
      {
        'Su': 'Sunday',
        'Mo': 'Monday',
        'Tu': 'Tuesday',
        'We': 'Wednesday',
        'Th': 'Thursday',
        'Fr': 'Friday',
        'Sa': 'Saturday'
      }"/&gt;
      
     &amp;lt;xsl:message select="map:keys($map)"/&gt;
  &amp;lt;/xsl:template&gt;  

&amp;lt;/xsl:stylesheet&gt;&lt;/pre&gt;
&lt;/blockquote&gt; 
&lt;p&gt;
A list of map functions can be found here &lt;a href="http://www.w3.org/2005/xpath-functions/map/"&gt;http://www.w3.org/2005/xpath-functions/map/&lt;/a&gt;,
though not all are available, as Saxon HE still does not allow inline functions.
&lt;/p&gt;
&lt;p&gt;
P.S. From the development perspective it&amp;#39;s a great harm that Saxon HE is so limited.
Basically limited to xslt 2.0 + some selected parts of 3.0.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=824d5dcd-a1a5-4314-b7fa-1e4447417c9f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,824d5dcd-a1a5-4314-b7fa-1e4447417c9f.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=acbef9ad-de11-4fea-b74e-d5c9a619ba50</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=acbef9ad-de11-4fea-b74e-d5c9a619ba50</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Lately we do not program in XSLT too often but rather in java, C#, SQL and javascript,
but from time to time we have tasks in XSLT.
</p>
        <p>
People claim that those languages are too different and use this argument to explain
why XSLT is only a niche language. We, on the other hand, often spot similarities
between them.
</p>
        <p>
So, what it is in other languages that is implemented as tunnel parameters in XSLT?
</p>
        <p>
To get an answer we reiterated how they work in XSLT, so, you:
</p>
        <ul>
          <li>
define a template with parameters marked as <code>tunnel="yes"</code>;</li>
          <li>
use these parameters the same way as regular parameters;</li>
          <li>
pass template parameters down to other templates marking them as <code>tunnel="yes"</code>;</li>
        </ul>
        <p>
The important difference of regular template parameters from tunnel parameters is
that the tunnel parameters are implicitly passed down the call chain of templates.
This means that you:
</p>
        <ul>
          <li>
define your API that is expected to receive some parameter;</li>
          <li>
pass these parameters somewhere high in the stack, or override them later in the stack
chain;</li>
          <li>
do not bother to propagate them (you might not even know all of the tunnel parameters
passed, so encapsulation is in action);</li>
        </ul>
        <p>
As a result we have a template with some parameters passed explicitly, and some others
are receiving values from somewhere, usually not from direct caller. It’s possible
to say that these tunnel parameters are injected into a template call. This resembles
a lot injection API in other languages where you configure that some parameters are
prepared for you by some container rather then by direct caller.
</p>
        <p>
Now, when we have expressed this idea it seems so obvious but before we thought of
this we did not realize that tunnel parameters in XSLT and Dependency Injection in
other languages are the same thing.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=acbef9ad-de11-4fea-b74e-d5c9a619ba50" />
      </body>
      <title>View on tunnel parameters in XSLT</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2017/03/26/ViewOnTunnelParametersInXSLT.aspx</link>
      <pubDate>Sun, 26 Mar 2017 04:21:36 GMT</pubDate>
      <description>&lt;p&gt;
Lately we do not program in XSLT too often but rather in java, C#, SQL and javascript,
but from time to time we have tasks in XSLT.
&lt;/p&gt;
&lt;p&gt;
People claim that those languages are too different and use this argument to explain
why XSLT is only a niche language. We, on the other hand, often spot similarities
between them.
&lt;/p&gt;
&lt;p&gt;
So, what it is in other languages that is implemented as tunnel parameters in XSLT?
&lt;/p&gt;
&lt;p&gt;
To get an answer we reiterated how they work in XSLT, so, you:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
define a template with parameters marked as &lt;code&gt;tunnel="yes"&lt;/code&gt;;&lt;/li&gt;
&lt;li&gt;
use these parameters the same way as regular parameters;&lt;/li&gt;
&lt;li&gt;
pass template parameters down to other templates marking them as &lt;code&gt;tunnel="yes"&lt;/code&gt;;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
The important difference of regular template parameters from tunnel parameters is
that the tunnel parameters are implicitly passed down the call chain of templates.
This means that you:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
define your API that is expected to receive some parameter;&lt;/li&gt;
&lt;li&gt;
pass these parameters somewhere high in the stack, or override them later in the stack
chain;&lt;/li&gt;
&lt;li&gt;
do not bother to propagate them (you might not even know all of the tunnel parameters
passed, so encapsulation is in action);&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As a result we have a template with some parameters passed explicitly, and some others
are receiving values from somewhere, usually not from direct caller. It’s possible
to say that these tunnel parameters are injected into a template call. This resembles
a lot injection API in other languages where you configure that some parameters are
prepared for you by some container rather then by direct caller.
&lt;/p&gt;
&lt;p&gt;
Now, when we have expressed this idea it seems so obvious but before we thought of
this we did not realize that tunnel parameters in XSLT and Dependency Injection in
other languages are the same thing.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=acbef9ad-de11-4fea-b74e-d5c9a619ba50" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,acbef9ad-de11-4fea-b74e-d5c9a619ba50.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=6232d896-acc1-4861-b593-e837578557b5</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=6232d896-acc1-4861-b593-e837578557b5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently we have found and fixed a bug in unreachable statement optimization in jxom.
</p>
        <p>
Latest version of stylesheets can be found at <a href="https://github.com/nesterovsky-bros/languages-xom">github.com
languages-xom</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6232d896-acc1-4861-b593-e837578557b5" />
      </body>
      <title>Languages XOM update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/12/21/LanguagesXOMUpdate.aspx</link>
      <pubDate>Wed, 21 Dec 2016 22:10:06 GMT</pubDate>
      <description>&lt;p&gt;
Recently we have found and fixed a bug in unreachable statement optimization in jxom.
&lt;/p&gt;
&lt;p&gt;
Latest version of stylesheets can be found at &lt;a href="https://github.com/nesterovsky-bros/languages-xom"&gt;github.com
languages-xom&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=6232d896-acc1-4861-b593-e837578557b5" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,6232d896-acc1-4861-b593-e837578557b5.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=0aac17ae-3e58-4605-89bf-8488c3554d82</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0aac17ae-3e58-4605-89bf-8488c3554d82.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,0aac17ae-3e58-4605-89bf-8488c3554d82.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=0aac17ae-3e58-4605-89bf-8488c3554d82</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Good bad and good news. 
</p>
        <dl>
          <dt>Good: recently a new version Saxon XSLT processor was published:</dt>
          <dd>
            <p>
              <b>12 May 2016</b>
              <br />
              <b>Saxon 9.7.0.5</b> maintenance release for Java and .NET. 
</p>
          </dd>
          <dt>Bad: we run that release on our code base and found a bug:</dt>
          <dd>
            <p>
See <a href="https://saxonica.plan.io/boards/3/topics/6423?pn=1&amp;r=6441#message-6441">Internal
error in Saxon-HE-9.7.0-5</a></p>
          </dd>
          <dt>Good: Michael Kay has confirmed the problem and even fixed it:</dt>
          <dd>
            <p>
See <a href="https://saxonica.plan.io/issues/2770">Bug #2770</a></p>
          </dd>
          <dt>The only missing ingredient is when the patch will be available to the public:</dt>
          <dd>
            <p>
"We tend to do a new maintenance release every 4-6 weeks. Can't commit to firm dates."
</p>
          </dd>
        </dl>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0aac17ae-3e58-4605-89bf-8488c3554d82" />
      </body>
      <title>Saxon-HE-9.7.0-5</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0aac17ae-3e58-4605-89bf-8488c3554d82.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/06/03/SaxonHE9705.aspx</link>
      <pubDate>Fri, 03 Jun 2016 21:09:10 GMT</pubDate>
      <description>  &lt;p&gt;
Good bad and good news. 
&lt;/p&gt;
&lt;dl&gt;
&lt;dt&gt;Good: recently a new version Saxon XSLT processor was published:&lt;/dt&gt; 
&lt;dd&gt;
&lt;p&gt;
&lt;b&gt;12 May 2016&lt;/b&gt;
&lt;br /&gt;
&lt;b&gt;Saxon 9.7.0.5&lt;/b&gt; maintenance release for Java and .NET. 
&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;Bad: we run that release on our code base and found a bug:&lt;/dt&gt; 
&lt;dd&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/boards/3/topics/6423?pn=1&amp;amp;r=6441#message-6441"&gt;Internal
error in Saxon-HE-9.7.0-5&lt;/a&gt; 
&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;Good: Michael Kay has confirmed the problem and even fixed it:&lt;/dt&gt; 
&lt;dd&gt;
&lt;p&gt;
See &lt;a href="https://saxonica.plan.io/issues/2770"&gt;Bug #2770&lt;/a&gt;
&lt;/p&gt;
&lt;/dd&gt;
&lt;dt&gt;The only missing ingredient is when the patch will be available to the public:&lt;/dt&gt; 
&lt;dd&gt;
&lt;p&gt;
"We tend to do a new maintenance release every 4-6 weeks. Can't commit to firm dates."
&lt;/p&gt;
&lt;/dd&gt;
&lt;/dl&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0aac17ae-3e58-4605-89bf-8488c3554d82" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,0aac17ae-3e58-4605-89bf-8488c3554d82.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=a57f50da-da1f-44f4-9572-cbc7e5434fa1</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a57f50da-da1f-44f4-9572-cbc7e5434fa1.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,a57f50da-da1f-44f4-9572-cbc7e5434fa1.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=a57f50da-da1f-44f4-9572-cbc7e5434fa1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <a href="https://en.wikipedia.org/wiki/Visitor_pattern">Visitor pattern</a> is often
used to separate operation from object graph it operates with. Here we assume that
the reader is familiar with the subject.
</p>
        <p>
The idea is like this:
</p>
        <ul>
          <li>
The operation over object graph is implemented as type called <code>Visitor</code>.</li>
          <li>
            <code>Visitor</code> defines methods for each type of object in the graph, which a
called during traversing of the graph.</li>
          <li>
Traversing over the graph is implemented by a type called <code>Traverser</code>,
or by the <code>Visitor</code> or by each object type in the graph.</li>
        </ul>
        <p>
Implementation should collect, aggregate or perform other actions during visit of
objects in the graph, so that at the end of the visit the purpose of operation will
be complete.
</p>
        <p>
Such implementation is push-like: you create operation object and call a method that
gets object graph on input and returns operation result on output.
</p>
        <p style="direction: ltr">
In the past we often dealt with big graphs (usually these are virtual graphs backended
at database or at a file system).
</p>
        <p>
Also having a strong experience in the XSLT we see that the visitor pattern in OOP
is directly mapped into <code>xsl:template</code> and <code>xsl:apply-templates</code> technique.
</p>
        <p>
Another thought was that in XML processing there are two camps:
</p>
        <ul>
          <li>
SAX (push-like) - those who process xml in callbacks, which is very similar to visitor
pattern; and</li>
          <li>
XML Reader (pull-like) - those who pull xml components from a source, and then iterate
and process them.</li>
        </ul>
        <p>
As with SAX vs XML Reader or, more generally, push vs pull processing models, there
is no the best one. One or the other is preferable in particular circumstances. E.g.
Pull like component fits into a transformation pipeline where one pull component has
another as its source; another example is when one needs to process two sources at
once, which is untrivial with push like model. On the other hand push processing fits
better into Reduce part of <a href="https://en.wikipedia.org/wiki/MapReduce">MapReduce</a> pattern
where you need to accumulate results from source.
</p>
        <p>
So, our idea was to complete classic push-like visitor pattern with an example of
pull-like implementation.
</p>
        <p>
For the demostration we have selected Java language, and a simplest boolean expression
calculator.
</p>
        <p>
Please follow GitHub <a href="https://github.com/nesterovsky-bros/VisitorPattern">nesterovsky-bros/VisitorPattern</a> to
see the detailed explanation.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a57f50da-da1f-44f4-9572-cbc7e5434fa1" />
      </body>
      <title>Pull visitor pattern</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a57f50da-da1f-44f4-9572-cbc7e5434fa1.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/02/09/PullVisitorPattern.aspx</link>
      <pubDate>Tue, 09 Feb 2016 12:37:10 GMT</pubDate>
      <description>&lt;p&gt;
&lt;a href="https://en.wikipedia.org/wiki/Visitor_pattern"&gt;Visitor pattern&lt;/a&gt; is often
used to separate operation from object graph it operates with. Here we assume that
the reader is familiar with the subject.
&lt;/p&gt;
&lt;p&gt;
The idea is like this:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
The operation over object graph is implemented as type called &lt;code&gt;Visitor&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Visitor&lt;/code&gt; defines methods for each type of object in the graph, which a
called during traversing of the graph.&lt;/li&gt;
&lt;li&gt;
Traversing over the graph is implemented by a type called &lt;code&gt;Traverser&lt;/code&gt;,
or by the &lt;code&gt;Visitor&lt;/code&gt; or by each object type in the graph.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Implementation should collect, aggregate or perform other actions during visit of
objects in the graph, so that at the end of the visit the purpose of operation will
be complete.
&lt;/p&gt;
&lt;p&gt;
Such implementation is push-like: you create operation object and call a method that
gets object graph on input and returns operation result on output.
&lt;/p&gt;
&lt;p style="direction: ltr"&gt;
In the past we often dealt with big graphs (usually these are virtual graphs backended
at database or at a file system).
&lt;/p&gt;
&lt;p&gt;
Also having a strong experience in the XSLT we see that the visitor pattern in OOP
is directly mapped into &lt;code&gt;xsl:template&lt;/code&gt; and &lt;code&gt;xsl:apply-templates&lt;/code&gt; technique.
&lt;/p&gt;
&lt;p&gt;
Another thought was that in XML processing there are two camps:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
SAX (push-like) - those who process xml in callbacks, which is very similar to visitor
pattern; and&lt;/li&gt;
&lt;li&gt;
XML Reader (pull-like) - those who pull xml components from a source, and then iterate
and process them.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As with SAX vs XML Reader or, more generally, push vs pull processing models, there
is no the best one. One or the other is preferable in particular circumstances. E.g.
Pull like component fits into a transformation pipeline where one pull component has
another as its source; another example is when one needs to process two sources at
once, which is untrivial with push like model. On the other hand push processing fits
better into Reduce part of &lt;a href="https://en.wikipedia.org/wiki/MapReduce"&gt;MapReduce&lt;/a&gt; pattern
where you need to accumulate results from source.
&lt;/p&gt;
&lt;p&gt;
So, our idea was to complete classic push-like visitor pattern with an example of
pull-like implementation.
&lt;/p&gt;
&lt;p&gt;
For the demostration we have selected Java language, and a simplest boolean expression
calculator.
&lt;/p&gt;
&lt;p&gt;
Please follow GitHub &lt;a href="https://github.com/nesterovsky-bros/VisitorPattern"&gt;nesterovsky-bros/VisitorPattern&lt;/a&gt; to
see the detailed explanation.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a57f50da-da1f-44f4-9572-cbc7e5434fa1" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,a57f50da-da1f-44f4-9572-cbc7e5434fa1.aspx</comments>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=d17e5531-b143-46d3-9b69-4f05e7f3b04f</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d17e5531-b143-46d3-9b69-4f05e7f3b04f.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d17e5531-b143-46d3-9b69-4f05e7f3b04f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Essence of the problem (see <a href="http://www.nesterovsky-bros.com/weblog/2016/01/02/ErrorDuringTransformationInSaxon97.aspx">Error
during transformation in Saxon 9.7</a>, <a href="https://saxonica.plan.io/boards/3/topics/6270">thread
on forum</a>):
</p>
        <ol>
          <li>
XPath engine may arbitrary reorder predicates whose expressions do not depend on a
context position.</li>
          <li>
While an XPath expression <code>$N[@x castable as xs:date][xs:date(@x) gt xs:date("2000-01-01")]</code> cannot
raise an error if it's evaluated from the left to right, an expression with reordered
predicates <code>$N[xs:date(@x) gt xs:date("2000-01-01")][@x castable as xs:date]</code> may
generate an error when <code>@x</code> is not a <code>xs:date</code>.</li>
        </ol>
        <p>
To avoid a potential problem one should rewrite the expression like this: <code>$N[if
(@x castable as xs:date) then xs:date(@x) gt xs:date("2000-01-01") else false()]</code>.
</p>
        <p>
Please note that the following rewrite will not work: <code>$N[(@x castable as xs:date)
and (xs:date(@x) gt xs:date("2000-01-01"))]</code>, as arguments of <code>and</code> expression
can be evaluated in any order, and error that occurs during evaluation of any argument
may be propageted.
</p>
        <p>
With these facts we faced a task to check our code base and to fix possible problems. 
</p>
        <p>
A search has brought ~450 instances of XPath expessions that use two or more consequtive
predicates. Accurate analysis limited this to ~20 instances that should be rewritten.
But then, all of sudden, we have decided to commit an experiment. What if we split
XPath expression in two sub expressions. Can error still resurface?
</p>
        <p>
Consider:
</p>
        <blockquote>
          <code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;<br /><br />
  &lt;xsl:variable name="elements" as="element()+"&gt;&lt;a/&gt;&lt;b value="c"/&gt;&lt;/xsl:variable&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:variable name="a" as="element()*" select="$elements[self::d
or self::e]"/&gt;<br />
    &lt;xsl:variable name="b" as="element()*" select="$a[xs:integer(@value)
= 1]"/&gt;<br /><br />
    &lt;xsl:sequence select="$b"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt;</code>
        </blockquote>
        <p>
As we expected Saxon 9.7 internally assembles a final XPath with two predicates and
reorders them. As result we get an error:
</p>
        <blockquote>
          <code>Error at char 20 in xsl:variable/@select on line 8 column 81 of
Saxon9.7-filter_speculation.xslt:<br />
  FORG0001: Cannot convert string "c" to an integer</code>
        </blockquote>
        <p>
This turn of events greately complicates the code review we have to commit.
</p>
        <p>
Michiel Kay's answer to this example:
</p>
        <blockquote>
          <i>I think your argument that the reordering is inappropriate when the
expression is written using variables is very powerful. I shall raise the question
with my WG colleagues.</i>
        </blockquote>
        <p>
In fact we think that either: reordering of predicates is inappropriate, or (weaker,
to allow reordering) to treat an error during evaluation of predicate expression as <code>false()</code>.
This is what is done in XSLT patterns. Other solutions make XPath less intuitive. 
</p>
        <p>
In other words we should use XPath (language) to express ideas, and engine should
correctly and efficiently implement them. So, we should not be forced to rewrite expression
to please implementation.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d17e5531-b143-46d3-9b69-4f05e7f3b04f" />
      </body>
      <title>Error during transformation in Saxon 9.7 - Continue</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d17e5531-b143-46d3-9b69-4f05e7f3b04f.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/01/04/ErrorDuringTransformationInSaxon97Continue.aspx</link>
      <pubDate>Mon, 04 Jan 2016 10:07:12 GMT</pubDate>
      <description>  &lt;p&gt;
Essence of the problem (see &lt;a href="http://www.nesterovsky-bros.com/weblog/2016/01/02/ErrorDuringTransformationInSaxon97.aspx"&gt;Error
during transformation in Saxon 9.7&lt;/a&gt;, &lt;a href="https://saxonica.plan.io/boards/3/topics/6270"&gt;thread
on forum&lt;/a&gt;):
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
XPath engine may arbitrary reorder predicates whose expressions do not depend on a
context position.&lt;/li&gt;
&lt;li&gt;
While an XPath expression &lt;code&gt;$N[@x castable as xs:date][xs:date(@x) gt xs:date("2000-01-01")]&lt;/code&gt; cannot
raise an error if it&amp;#39;s evaluated from the left to right, an expression with reordered
predicates &lt;code&gt;$N[xs:date(@x) gt xs:date("2000-01-01")][@x castable as xs:date]&lt;/code&gt; may
generate an error when &lt;code&gt;@x&lt;/code&gt; is not a &lt;code&gt;xs:date&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
To avoid a potential problem one should rewrite the expression like this: &lt;code&gt;$N[if
(@x castable as xs:date) then xs:date(@x) gt xs:date("2000-01-01") else false()]&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
Please note that the following rewrite will not work: &lt;code&gt;$N[(@x castable as xs:date)
and (xs:date(@x) gt xs:date("2000-01-01"))]&lt;/code&gt;, as arguments of &lt;code&gt;and&lt;/code&gt; expression
can be evaluated in any order, and error that occurs during evaluation of any argument
may be propageted.
&lt;/p&gt;
&lt;p&gt;
With these facts we faced a task to check our code base and to fix possible problems. 
&lt;/p&gt;
&lt;p&gt;
A search has brought ~450 instances of XPath expessions that use two or more consequtive
predicates. Accurate analysis limited this to ~20 instances that should be rewritten.
But then, all of sudden, we have decided to commit an experiment. What if we split
XPath expression in two sub expressions. Can error still resurface?
&lt;/p&gt;
&lt;p&gt;
Consider:
&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;&amp;lt;xsl:stylesheet version="2.0" xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform"&gt;http://www.w3.org/1999/XSL/Transform&lt;/a&gt;"&lt;br /&gt;
&amp;nbsp; xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:variable name="elements" as="element()+"&gt;&amp;lt;a/&gt;&amp;lt;b value="c"/&gt;&amp;lt;/xsl:variable&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:template match="/"&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;lt;xsl:variable name="a" as="element()*" select="$elements[self::d
or self::e]"/&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:variable name="b" as="element()*" select="$a[xs:integer(@value)
= 1]"/&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:sequence select="$b"/&gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xsl:template&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&gt;&lt;/code&gt;&lt;/blockquote&gt; 
&lt;p&gt;
As we expected Saxon 9.7 internally assembles a final XPath with two predicates and
reorders them. As result we get an error:
&lt;/p&gt;
&lt;blockquote&gt; &lt;code&gt;Error at char 20 in xsl:variable/@select on line 8 column 81 of
Saxon9.7-filter_speculation.xslt:&lt;br /&gt;
&amp;nbsp; FORG0001: Cannot convert string "c" to an integer&lt;/code&gt; &lt;/blockquote&gt; 
&lt;p&gt;
This turn of events greately complicates the code review we have to commit.
&lt;/p&gt;
&lt;p&gt;
Michiel Kay&amp;#39;s answer to this example:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;I think your argument that the reordering is inappropriate when the
expression is written using variables is very powerful. I shall raise the question
with my WG colleagues.&lt;/i&gt;&lt;/blockquote&gt; 
&lt;p&gt;
In fact we think that either: reordering of predicates is inappropriate, or (weaker,
to allow reordering) to treat an error during evaluation of predicate expression as &lt;code&gt;false()&lt;/code&gt;.
This is what is done in XSLT patterns. Other solutions make XPath less intuitive. 
&lt;/p&gt;
&lt;p&gt;
In other words we should use XPath (language) to express ideas, and engine should
correctly and efficiently implement them. So, we should not be forced to rewrite expression
to please implementation.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d17e5531-b143-46d3-9b69-4f05e7f3b04f" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d17e5531-b143-46d3-9b69-4f05e7f3b04f.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=0440711a-6c3c-4d59-b2e6-ba41f64c1c0c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0440711a-6c3c-4d59-b2e6-ba41f64c1c0c.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=0440711a-6c3c-4d59-b2e6-ba41f64c1c0c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
On December, 30 we have opened <a href="https://saxonica.plan.io/boards/3/topics/6270">a
thread in Saxon help forum</a> that shows a stylesheet generating an error. This is
the stylesheet:
</p>
        <blockquote>
          <code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>"<br />
  xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;<br /><br />
  &lt;xsl:variable name="elements" as="element()+"&gt;&lt;a/&gt;&lt;b value="c"/&gt;&lt;/xsl:variable&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:sequence select="$elements[self::d or self::e][xs:integer(@value)
= 1]"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt;</code>
        </blockquote>
        <p>
We get an error:
</p>
        <blockquote>
          <code>Error at char 47 in xsl:sequence/@select on line 7 column 83 of
Saxon9.7-filter_speculation.xslt:<br />
  FORG0001: Cannot convert string "c" to an integer<br />
Exception in thread "main" ; SystemID: .../Saxon9.7-filter_speculation.xslt; Line#:
7; Column#: 47<br />
ValidationException: Cannot convert string "c" to an integer<br />
  at ... </code>
        </blockquote>
        <p>
It's interesting that error happens in Saxon 9.7 but not in earlier versions.
</p>
        <p>
The answer we got was expected but disheartening:
</p>
        <blockquote>
          <i>The XPath specification (section 2.3.4, Errors and Optimization) explicitly
allows the predicates of a filter expression to be reordered by an optimizer. See
this example, which is very similar to yours:</i>
          <blockquote>
            <p>
              <i>The expression in the following example cannot raise a casting error if it is evaluated
exactly as written (i.e., left to right). Since neither predicate depends on the context
position, an implementation might choose to reorder the predicates to achieve better
performance (for example, by taking advantage of an index). This reordering could
cause the expression to raise an error.</i>
            </p>
            <pre>$N[@x castable as xs:date][xs:date(@x) gt xs:date("2000-01-01")]</pre>
          </blockquote>
        </blockquote>
        <p>
Following the spec, Michael Kay advices us to rewrite XPath:
</p>
        <blockquote>
          <code>$elements[self::d or self::e][xs:integer(@value) = 1]</code>
        </blockquote>
        <p>
like this:
</p>
        <blockquote>
          <code>$elements[if (self::d or self::e) then xs:integer(@value) = 1 else
false()]</code>
        </blockquote>
        <p>
Such subtleties make it hard to reason about and to teach XPath. We doubt many people
will spot the difference immediately.
</p>
        <p>
We think that if such optimization was so much important to spec writers, then they
had to change filter rules to treat failed predicates as <code>false()</code>. This
would avoid any obscure differences in these two, otherwise equal, expressions. In
fact something <a href="http://www.nesterovsky-bros.com/weblog/2008/07/31/SFINAEInXsltOrNativeExceptionHandling.aspx">similar
already exists with templates</a> where failed evaluation of pattern is treated as
un-match.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0440711a-6c3c-4d59-b2e6-ba41f64c1c0c" />
      </body>
      <title>Error during transformation in Saxon 9.7</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,0440711a-6c3c-4d59-b2e6-ba41f64c1c0c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2016/01/02/ErrorDuringTransformationInSaxon97.aspx</link>
      <pubDate>Sat, 02 Jan 2016 21:32:16 GMT</pubDate>
      <description>  &lt;p&gt;
On December, 30 we have opened &lt;a href="https://saxonica.plan.io/boards/3/topics/6270"&gt;a
thread in Saxon help forum&lt;/a&gt; that shows a stylesheet generating an error. This is
the stylesheet:
&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;&amp;lt;xsl:stylesheet version="2.0" xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform"&gt;http://www.w3.org/1999/XSL/Transform&lt;/a&gt;"&lt;br /&gt;
&amp;nbsp; xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:variable name="elements" as="element()+"&gt;&amp;lt;a/&gt;&amp;lt;b value="c"/&gt;&amp;lt;/xsl:variable&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:template match="/"&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:sequence select="$elements[self::d or self::e][xs:integer(@value)
= 1]"/&gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xsl:template&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&gt;&lt;/code&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We get an error:
&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;Error at char 47 in xsl:sequence/@select on line 7 column 83 of
Saxon9.7-filter_speculation.xslt:&lt;br /&gt;
&amp;nbsp; FORG0001: Cannot convert string "c" to an integer&lt;br /&gt;
Exception in thread "main" ; SystemID: .../Saxon9.7-filter_speculation.xslt; Line#:
7; Column#: 47&lt;br /&gt;
ValidationException: Cannot convert string "c" to an integer&lt;br /&gt;
&amp;nbsp; at ... &lt;/code&gt;&lt;/blockquote&gt; 
&lt;p&gt;
It&amp;#39;s interesting that error happens in Saxon 9.7 but not in earlier versions.
&lt;/p&gt;
&lt;p&gt;
The answer we got was expected but disheartening:
&lt;/p&gt;
&lt;blockquote&gt;&lt;i&gt;The XPath specification (section 2.3.4, Errors and Optimization) explicitly
allows the predicates of a filter expression to be reordered by an optimizer. See
this example, which is very similar to yours:&lt;/i&gt; &lt;blockquote&gt; 
&lt;p&gt;
&lt;i&gt;The expression in the following example cannot raise a casting error if it is evaluated
exactly as written (i.e., left to right). Since neither predicate depends on the context
position, an implementation might choose to reorder the predicates to achieve better
performance (for example, by taking advantage of an index). This reordering could
cause the expression to raise an error.&lt;/i&gt;
&lt;/p&gt;
&lt;pre&gt;$N[@x castable as xs:date][xs:date(@x) gt xs:date(&amp;quot;2000-01-01&amp;quot;)]&lt;/pre&gt;
&lt;/blockquote&gt; &lt;/blockquote&gt; 
&lt;p&gt;
Following the spec, Michael Kay advices us to rewrite XPath:
&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;$elements[self::d or self::e][xs:integer(@value) = 1]&lt;/code&gt;&lt;/blockquote&gt; 
&lt;p&gt;
like this:
&lt;/p&gt;
&lt;blockquote&gt;&lt;code&gt;$elements[if (self::d or self::e) then xs:integer(@value) = 1 else
false()]&lt;/code&gt;&lt;/blockquote&gt; 
&lt;p&gt;
Such subtleties make it hard to reason about and to teach XPath. We doubt many people
will spot the difference immediately.
&lt;/p&gt;
&lt;p&gt;
We think that if such optimization was so much important to spec writers, then they
had to change filter rules to treat failed predicates as &lt;code&gt;false()&lt;/code&gt;. This
would avoid any obscure differences in these two, otherwise equal, expressions. In
fact something &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/07/31/SFINAEInXsltOrNativeExceptionHandling.aspx"&gt;similar
already exists with templates&lt;/a&gt; where failed evaluation of pattern is treated as
un-match.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=0440711a-6c3c-4d59-b2e6-ba41f64c1c0c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,0440711a-6c3c-4d59-b2e6-ba41f64c1c0c.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=fa5d6281-2d3e-430a-8583-40c6b30b9536</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fa5d6281-2d3e-430a-8583-40c6b30b9536.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fa5d6281-2d3e-430a-8583-40c6b30b9536.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=fa5d6281-2d3e-430a-8583-40c6b30b9536</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It's time to align csharpxom to the latest version of C#. The article <a href="https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C#-6">New
Language Features in C# 6</a> sums up what's being added.
</p>
        <p>
Sources can be found at <a href="https://github.com/nesterovsky-bros/languages-xom">nesterovsky-bros/languages-xom</a>,
and C# model is at <a href="https://github.com/nesterovsky-bros/languages-xom/tree/master/csharpxom">csharp
folder</a>.
</p>
        <p>
In general we feel hostile to any new features until they prove they bring an added
value. So, here our list of new features from most to least useless:
</p>
        <ol>
          <li>
            <p>
String interpolation
</p>
            <p>
              <code>var s = $"{p.Name} is {p.Age} year{{s}} old";</code>
            </p>
            <p>
This is useless, as it does not account resource localization.
</p>
          </li>
          <li>
            <p>
Null-conditional operators
</p>
            <p>
              <code>int? first = customers?[0].Orders?.Count();</code>
            </p>
            <p>
They claim to reduce cluttering from null checks, but in our opinion it looks opposite.
It's better to get NullReferenceException if arguments are wrong.
</p>
          </li>
          <li>
            <p>
Exception filters
</p>
            <p>
              <code>private static bool Log(Exception e) { /* log it */ ; return false; }<br />
…<br />
try { … } catch (Exception e) when (Log(e)) {}</code>
            </p>
            <p>
              <i>"It is also a common and accepted form of “abuse” to use exception filters
for side effects; e.g. logging."</i>
            </p>
            <p>
Design a feature for abuse just does not tastes good.
</p>
          </li>
          <li>
            <p>
Expression-bodied function and property members.
</p>
            <p>
              <code>public Point Move(int dx, int dy) =&gt; new Point(x + dx, y + dy);<br />
public string Name =&gt; First + " " + Last;</code>
            </p>
            <p>
Not sure it's that usefull.
</p>
          </li>
        </ol>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fa5d6281-2d3e-430a-8583-40c6b30b9536" />
      </body>
      <title>Support C# 6.0 in languages xom</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,fa5d6281-2d3e-430a-8583-40c6b30b9536.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2015/08/24/SupportC60InLanguagesXom.aspx</link>
      <pubDate>Mon, 24 Aug 2015 10:52:07 GMT</pubDate>
      <description>  &lt;p&gt;
It&amp;#39;s time to align csharpxom to the latest version of C#. The article &lt;a href="https://github.com/dotnet/roslyn/wiki/New-Language-Features-in-C#-6"&gt;New
Language Features in C# 6&lt;/a&gt; sums up what&amp;#39;s being added.
&lt;/p&gt;
&lt;p&gt;
Sources can be found at &lt;a href="https://github.com/nesterovsky-bros/languages-xom"&gt;nesterovsky-bros/languages-xom&lt;/a&gt;,
and C# model is at &lt;a href="https://github.com/nesterovsky-bros/languages-xom/tree/master/csharpxom"&gt;csharp
folder&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
In general we feel hostile to any new features until they prove they bring an added
value. So, here our list of new features from most to least useless:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;
String interpolation
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;var s = $"{p.Name} is {p.Age} year{{s}} old";&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This is useless, as it does not account resource localization.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
Null-conditional operators
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;int? first = customers?[0].Orders?.Count();&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
They claim to reduce cluttering from null checks, but in our opinion it looks opposite.
It's better to get NullReferenceException if arguments are wrong.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
Exception filters
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;private static bool Log(Exception e) { /* log it */ ; return false; }&lt;br /&gt;
…&lt;br /&gt;
try { … } catch (Exception e) when (Log(e)) {}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;i&gt;&amp;quot;It is also a common and accepted form of “abuse” to use exception filters
for side effects; e.g. logging.&amp;quot;&lt;/i&gt;
&lt;/p&gt;
&lt;p&gt;
Design a feature for abuse just does not tastes good.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
Expression-bodied function and property members.
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;public Point Move(int dx, int dy) =&gt; new Point(x + dx, y + dy);&lt;br /&gt;
public string Name =&gt; First + " " + Last;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Not sure it&amp;#39;s that usefull.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=fa5d6281-2d3e-430a-8583-40c6b30b9536" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,fa5d6281-2d3e-430a-8583-40c6b30b9536.aspx</comments>
      <category>.NET</category>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=06491dbf-8972-45ea-8f00-b6e1b0782a00</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,06491dbf-8972-45ea-8f00-b6e1b0782a00.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,06491dbf-8972-45ea-8f00-b6e1b0782a00.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=06491dbf-8972-45ea-8f00-b6e1b0782a00</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Taking into an account that we use Saxon for many years, it was strange to run into
so simple error like the following:
</p>
        <blockquote>
          <pre>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:template match="/"&gt;
    &lt;xsl:variable name="doc" as="element()+"&gt;&lt;a/&gt;&lt;b/&gt;&lt;c/&gt;&lt;/xsl:variable&gt;   
    &lt;xsl:sequence select="$doc = 3"/&gt;
  &lt;/xsl:template&gt;
&lt;/xsl:stylesheet&gt;
</pre>
        </blockquote>
        <p>
This is a simplified case that should produce an dynamic error FORG0001 as per <a href="http://www.w3.org/TR/xpath20/#id-general-comparisons">General
Comparisions</a>; the real code is more complex, as it uses <a href="http://www.nesterovsky-bros.com/weblog/2008/07/31/SFINAEInXsltOrNativeExceptionHandling.aspx">SFINAE</a> and
continues.
</p>
        <p>
This case crushes in Saxon with exception:
</p>
        <blockquote>
          <pre>Exception in thread "main" java.lang.RuntimeException: 
      Internal error evaluating template  at line 3 in module ICE9.6.xslt
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail()
    at net.sf.saxon.trans.Mode.applyTemplates()
    at net.sf.saxon.Controller.transformDocument()
    at net.sf.saxon.Controller.transform()
    at net.sf.saxon.s9api.XsltTransformer.transform()
    at net.sf.saxon.jaxp.TransformerImpl.transform()
    ...
Caused by: java.lang.NumberFormatException: For input string: "" 
    at java.lang.NumberFormatException.forInputString()
    at java.lang.Long.parseLong()
    at java.lang.Long.parseLong()
    at net.sf.saxon.expr.GeneralComparison.quickCompare()
    at net.sf.saxon.expr.GeneralComparison.compare()
    at net.sf.saxon.expr.GeneralComparison.evaluateManyToOne()
    at net.sf.saxon.expr.GeneralComparison.evaluateItem()
    at net.sf.saxon.expr.GeneralComparison.evaluateItem()
    at net.sf.saxon.expr.Expression.process()
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail()
    ... 8 more
</pre>
        </blockquote>
        <p>
We have reported the problem at <a href="https://saxonica.plan.io/boards/3/topics/6165">Saxon's
forum</a>, and as usual the problem was shortly resolved.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=06491dbf-8972-45ea-8f00-b6e1b0782a00" />
      </body>
      <title>Internal Evaluation Error in Saxon 9.6</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,06491dbf-8972-45ea-8f00-b6e1b0782a00.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2015/07/31/InternalEvaluationErrorInSaxon96.aspx</link>
      <pubDate>Fri, 31 Jul 2015 08:36:39 GMT</pubDate>
      <description>  &lt;p&gt;
Taking into an account that we use Saxon for many years, it was strange to run into
so simple error like the following:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;&amp;lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &amp;lt;xsl:template match="/"&gt;
    &amp;lt;xsl:variable name="doc" as="element()+"&gt;&amp;lt;a/&gt;&amp;lt;b/&gt;&amp;lt;c/&gt;&amp;lt;/xsl:variable&gt;   
    &amp;lt;xsl:sequence select="$doc = 3"/&gt;
  &amp;lt;/xsl:template&gt;
&amp;lt;/xsl:stylesheet&gt;
&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
This is a simplified case that should produce an dynamic error FORG0001 as per &lt;a href="http://www.w3.org/TR/xpath20/#id-general-comparisons"&gt;General
Comparisions&lt;/a&gt;; the real code is more complex, as it uses &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/07/31/SFINAEInXsltOrNativeExceptionHandling.aspx"&gt;SFINAE&lt;/a&gt; and
continues.
&lt;/p&gt;
&lt;p&gt;
This case crushes in Saxon with exception:
&lt;/p&gt;
&lt;blockquote&gt;&lt;pre&gt;Exception in thread "main" java.lang.RuntimeException: 
      Internal error evaluating template  at line 3 in module ICE9.6.xslt
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail()
    at net.sf.saxon.trans.Mode.applyTemplates()
    at net.sf.saxon.Controller.transformDocument()
    at net.sf.saxon.Controller.transform()
    at net.sf.saxon.s9api.XsltTransformer.transform()
    at net.sf.saxon.jaxp.TransformerImpl.transform()
    ...
Caused by: java.lang.NumberFormatException: For input string: "" 
    at java.lang.NumberFormatException.forInputString()
    at java.lang.Long.parseLong()
    at java.lang.Long.parseLong()
    at net.sf.saxon.expr.GeneralComparison.quickCompare()
    at net.sf.saxon.expr.GeneralComparison.compare()
    at net.sf.saxon.expr.GeneralComparison.evaluateManyToOne()
    at net.sf.saxon.expr.GeneralComparison.evaluateItem()
    at net.sf.saxon.expr.GeneralComparison.evaluateItem()
    at net.sf.saxon.expr.Expression.process()
    at net.sf.saxon.expr.instruct.Template.applyLeavingTail()
    ... 8 more
&lt;/pre&gt;&lt;/blockquote&gt; 
&lt;p&gt;
We have reported the problem at &lt;a href="https://saxonica.plan.io/boards/3/topics/6165"&gt;Saxon&amp;#39;s
forum&lt;/a&gt;, and as usual the problem was shortly resolved.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=06491dbf-8972-45ea-8f00-b6e1b0782a00" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,06491dbf-8972-45ea-8f00-b6e1b0782a00.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ed13fb86-dca8-4d05-b8f5-2bc326d12591</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ed13fb86-dca8-4d05-b8f5-2bc326d12591.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ed13fb86-dca8-4d05-b8f5-2bc326d12591.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ed13fb86-dca8-4d05-b8f5-2bc326d12591</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After ECMAScript Xml Object Model we aligned JXOM to support Java 8. This includes
support of:
</p>
        <ul>
          <li>
Lambda Expressions - <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html">http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html</a></li>
          <li>
Method References - <a href="http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html">http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html</a><br /></li>
          <li>
Default Methods - <a href="http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html">http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html</a><br /></li>
        </ul>
        <p>
As with ECMAScript, all sources are available at <a href="https://github.com/nesterovsky-bros/languages-xom">https://github.com/nesterovsky-bros/languages-xom</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ed13fb86-dca8-4d05-b8f5-2bc326d12591" />
      </body>
      <title>Java 8 Xml Object Model</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ed13fb86-dca8-4d05-b8f5-2bc326d12591.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2015/04/09/Java8XmlObjectModel.aspx</link>
      <pubDate>Thu, 09 Apr 2015 19:46:22 GMT</pubDate>
      <description>  &lt;p&gt;
After ECMAScript Xml Object Model we aligned JXOM to support Java 8. This includes
support of:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Lambda Expressions - &lt;a href="http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html"&gt;http://docs.oracle.com/javase/tutorial/java/javaOO/lambdaexpressions.html&lt;/a&gt; 
&lt;/li&gt;
&lt;li&gt;
Method References - &lt;a href="http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html"&gt;http://docs.oracle.com/javase/tutorial/java/javaOO/methodreferences.html&lt;/a&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;li&gt;
Default Methods - &lt;a href="http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html"&gt;http://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html&lt;/a&gt;
&lt;br /&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
As with ECMAScript, all sources are available at &lt;a href="https://github.com/nesterovsky-bros/languages-xom"&gt;https://github.com/nesterovsky-bros/languages-xom&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ed13fb86-dca8-4d05-b8f5-2bc326d12591" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ed13fb86-dca8-4d05-b8f5-2bc326d12591.aspx</comments>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=86ad0d64-f0f4-42d7-a595-7f051dbbbc4c</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,86ad0d64-f0f4-42d7-a595-7f051dbbbc4c.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,86ad0d64-f0f4-42d7-a595-7f051dbbbc4c.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=86ad0d64-f0f4-42d7-a595-7f051dbbbc4c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Much time has passed since we fixed or extended <a href="http://www.nesterovsky-bros.com/weblog/2012/03/23/LanguagesXOMUpdate.aspx">Languages
Xml Object Model</a>. But now we needed to manipulate with and generate javascript
programs. 
</p>
        <p>
Though xslt today is not a language of choice but rather niche language, it still
fits very well to tasks of code generation and transformation.
</p>
        <p>
So, we're pleased to announce ECMAScript Xml Object Model, which includes:
</p>
        <ul>
          <li>
xml schema <a href="https://github.com/nesterovsky-bros/languages-xom/blob/master/ecmascriptxom/ecmascript.xsd">ecmasript.xsd</a>,
which is based on <a href="https://github.com/nesterovsky-bros/languages-xom/blob/master/ecmascriptxom/es6-draft.docx">ECMAScript
6<sup>th</sup> Edition / Draft February 20, 2015</a>; 
</li>
          <li>
a set of xslt to generate the text code, and perform some basic transformations over
the tree;</li>
          <li>
a set of smoke tests to verify the generation.</li>
        </ul>
        <p>
All sources are available at github: <a href="https://github.com/nesterovsky-bros/languages-xom">https://github.com/nesterovsky-bros/languages-xom</a></p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=86ad0d64-f0f4-42d7-a595-7f051dbbbc4c" />
      </body>
      <title>ECMAScript Xml Object Model</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,86ad0d64-f0f4-42d7-a595-7f051dbbbc4c.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2015/04/06/ECMAScriptXmlObjectModel.aspx</link>
      <pubDate>Mon, 06 Apr 2015 12:17:04 GMT</pubDate>
      <description>  &lt;p&gt;
Much time has passed since we fixed or extended &lt;a href="http://www.nesterovsky-bros.com/weblog/2012/03/23/LanguagesXOMUpdate.aspx"&gt;Languages
Xml Object Model&lt;/a&gt;. But now we needed to manipulate with and generate javascript
programs. 
&lt;/p&gt;
&lt;p&gt;
Though xslt today is not a language of choice but rather niche language, it still
fits very well to tasks of code generation and transformation.
&lt;/p&gt;
&lt;p&gt;
So, we&amp;#39;re pleased to announce ECMAScript Xml Object Model, which includes:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
xml schema &lt;a href="https://github.com/nesterovsky-bros/languages-xom/blob/master/ecmascriptxom/ecmascript.xsd"&gt;ecmasript.xsd&lt;/a&gt;,
which is based on &lt;a href="https://github.com/nesterovsky-bros/languages-xom/blob/master/ecmascriptxom/es6-draft.docx"&gt;ECMAScript
6&lt;sup&gt;th&lt;/sup&gt; Edition / Draft February 20, 2015&lt;/a&gt;; 
&lt;/li&gt;
&lt;li&gt;
a set of xslt to generate the text code, and perform some basic transformations over
the tree;&lt;/li&gt;
&lt;li&gt;
a set of smoke tests to verify the generation.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
All sources are available at github: &lt;a href="https://github.com/nesterovsky-bros/languages-xom"&gt;https://github.com/nesterovsky-bros/languages-xom&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=86ad0d64-f0f4-42d7-a595-7f051dbbbc4c" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,86ad0d64-f0f4-42d7-a595-7f051dbbbc4c.aspx</comments>
      <category>Announce</category>
      <category>javascript</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7f9a37f1-6cdf-488a-816d-608239e21713</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7f9a37f1-6cdf-488a-816d-608239e21713.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7f9a37f1-6cdf-488a-816d-608239e21713.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7f9a37f1-6cdf-488a-816d-608239e21713</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
After investigation we have found that Saxon 9.6 HE does not support xslt 3.0 as we
assumed earlier. 
</p>
        <p>
On <a href="http://www.saxonica.com/html/welcome/welcome.html">Saxonica site</a> it's
written: "Support for XQuery 3.0 and XPath 3.0 (now Recommendations) has been added
to the open-source product." 
</p>
        <p>
As one can notice no xslt is mentioned.
</p>
        <p>
More details are on <a href="https://saxonica.plan.io/boards/3/topics/6010">open-source
3.0 support</a>.
</p>
:-( <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7f9a37f1-6cdf-488a-816d-608239e21713" /></body>
      <title>Saxon 9.6 HE -xslt 3.0</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7f9a37f1-6cdf-488a-816d-608239e21713.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2014/10/06/Saxon96HEXslt30.aspx</link>
      <pubDate>Mon, 06 Oct 2014 10:16:03 GMT</pubDate>
      <description>&lt;p&gt;
After investigation we have found that Saxon 9.6 HE does not support xslt 3.0 as we
assumed earlier. 
&lt;/p&gt;
&lt;p&gt;
On &lt;a href="http://www.saxonica.com/html/welcome/welcome.html"&gt;Saxonica site&lt;/a&gt; it's
written: "Support for XQuery 3.0 and XPath 3.0 (now Recommendations) has been added
to the open-source product." 
&lt;/p&gt;
&lt;p&gt;
As one can notice no xslt is mentioned.
&lt;/p&gt;
&lt;p&gt;
More details are on &lt;a href="https://saxonica.plan.io/boards/3/topics/6010"&gt;open-source
3.0 support&lt;/a&gt;.
&lt;/p&gt;
:-( &lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7f9a37f1-6cdf-488a-816d-608239e21713" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7f9a37f1-6cdf-488a-816d-608239e21713.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=828be664-32d7-432c-a00b-ab347e4e1a9a</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,828be664-32d7-432c-a00b-ab347e4e1a9a.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,828be664-32d7-432c-a00b-ab347e4e1a9a.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=828be664-32d7-432c-a00b-ab347e4e1a9a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
The new release of Saxon HE (version 9.6) claims basic support of xslt 3.0. So we're
eager to test it but... errors happen. See error report at <a href="https://saxonica.plan.io/boards/2/topics/6006">Error
in SaxonHE9-6-0-1J</a> and <a href="https://saxonica.plan.io/issues/2160">Bug #2160</a>.
</p>
        <p>
As with previous release <a href="http://www.nesterovsky-bros.com/weblog/2014/07/14/ExceptionDuringExecutionInSaxonHE9516.aspx">Exception
during execution in Saxon-HE-9.5.1-6</a> we bumped into engine's internal error.
</p>
        <p>
We expect to see an update very soon, and to continue with long waited xslt 3.0.
</p>
        <p>
Here is an argument to the discussion of open source vs commercial projects: open
source projects with rich community may benefit, as problems are detected promptly;
while commercial projects risk to live with more unnoticed bugs.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=828be664-32d7-432c-a00b-ab347e4e1a9a" />
      </body>
      <title>Error in SaxonHE9-6-0-1J</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,828be664-32d7-432c-a00b-ab347e4e1a9a.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2014/10/05/ErrorInSaxonHE9601J.aspx</link>
      <pubDate>Sun, 05 Oct 2014 08:10:14 GMT</pubDate>
      <description>  &lt;p&gt;
The new release of Saxon HE (version 9.6) claims basic support of xslt 3.0. So we're
eager to test it but... errors happen. See error report at &lt;a href="https://saxonica.plan.io/boards/2/topics/6006"&gt;Error
in SaxonHE9-6-0-1J&lt;/a&gt; and &lt;a href="https://saxonica.plan.io/issues/2160"&gt;Bug #2160&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
As with previous release &lt;a href="http://www.nesterovsky-bros.com/weblog/2014/07/14/ExceptionDuringExecutionInSaxonHE9516.aspx"&gt;Exception
during execution in Saxon-HE-9.5.1-6&lt;/a&gt; we bumped into engine's internal error.
&lt;/p&gt;
&lt;p&gt;
We expect to see an update very soon, and to continue with long waited xslt 3.0.
&lt;/p&gt;
&lt;p&gt;
Here is an argument to the discussion of open source vs commercial projects: open
source projects with rich community may benefit, as problems are detected promptly;
while commercial projects risk to live with more unnoticed bugs.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=828be664-32d7-432c-a00b-ab347e4e1a9a" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,828be664-32d7-432c-a00b-ab347e4e1a9a.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7f261e36-02d1-40b2-bd9b-72e5097333bb</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7f261e36-02d1-40b2-bd9b-72e5097333bb.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7f261e36-02d1-40b2-bd9b-72e5097333bb.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7f261e36-02d1-40b2-bd9b-72e5097333bb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
With Saxon 9.6 we can finally play with open source xslt 3.0
</p>
        <p>
It's sad that it took so much time to make it available.
</p>
        <p>
See <a href="http://www.saxonica.com/html/welcome/welcome.html">Saxonica's home page</a> to
get details.
</p>
        <p>
          <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7f261e36-02d1-40b2-bd9b-72e5097333bb" />
        </p>
      </body>
      <title>Saxon 9.6</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7f261e36-02d1-40b2-bd9b-72e5097333bb.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2014/10/03/Saxon96.aspx</link>
      <pubDate>Fri, 03 Oct 2014 10:37:11 GMT</pubDate>
      <description>&lt;p&gt;
With Saxon 9.6 we can finally play with open source xslt 3.0
&lt;/p&gt;
&lt;p&gt;
It's sad that it took so much time to make it available.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="http://www.saxonica.com/html/welcome/welcome.html"&gt;Saxonica's home page&lt;/a&gt; to
get details.
&lt;/p&gt;
&lt;p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7f261e36-02d1-40b2-bd9b-72e5097333bb" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7f261e36-02d1-40b2-bd9b-72e5097333bb.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c3178b61-8e62-4ae7-b00a-4ebde095b3ef</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c3178b61-8e62-4ae7-b00a-4ebde095b3ef.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c3178b61-8e62-4ae7-b00a-4ebde095b3ef.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c3178b61-8e62-4ae7-b00a-4ebde095b3ef</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
These days we're not active xslt developers, though we still consider xslt and xquery
are important part of our personal experience and self education.
</p>
        <p>
Besides, we have a pretty large xslt code base that is and will be in use. We think
xslt/xquery is in use in many other big and small projects thus they have a strong
position as a niche languages.
</p>
        <p>
Thus we think it's important to help to those who support xslt/xquery engines. That's
what we're regularly doing (thanks to our code base). 
</p>
        <p>
Now, to the problem we just have found. Please consider the code:
</p>
        <p style="padding-left: 1em">
          <code> &lt;xsl:stylesheet version="2.0"<br />
  xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>" 
<br />
  xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>" 
<br />
  xmlns:t="this"<br />
  exclude-result-prefixes="xs t"&gt;<br /><br />
  &lt;xsl:template match="/"&gt;<br />
    &lt;xsl:param name="new-line-text" as="xs:string" select="'
'"/&gt;<br />
    &lt;xsl:variable name="items" as="item()*" select="'select', $new-line-text"/&gt;<br /><br />
    &lt;xsl:message select="t:string-join($items)"/&gt;<br />
  &lt;/xsl:template&gt;<br /><br />
  &lt;!--<br />
    Joins adjacent string items.<br />
      $items - items to join.<br />
      Returns joined items.<br />
  --&gt;<br />
  &lt;xsl:function name="t:string-join" as="item()*"&gt;<br />
    &lt;xsl:param name="items" as="item()*"/&gt;<br /><br />
    &lt;xsl:variable name="indices" as="xs:integer*" select="<br />
      0,<br />
      index-of<br />
      (<br />
        (<br />
          for $item in $items return<br />
            $item instance
of xs:string<br />
        ),<br />
        false()<br />
      ),<br />
      count($items) + 1"/&gt;<br /><br />
    &lt;xsl:sequence select="<br />
      for $i in 1 to count($indices) - 1 return<br />
      (<br />
        $items[$indices[$i]],<br />
        string-join<br />
        (<br />
          subsequence<br />
          (<br />
            $items,<br />
            $indices[$i] +
1,<br />
            $indices[$i + 1]
- $indices[$i] - 1<br />
          ),<br />
          ''<br />
        )<br />
      )"/&gt;<br />
  &lt;/xsl:function&gt;<br /><br />
&lt;/xsl:stylesheet&gt; </code>
        </p>
        <p>
The output is:
</p>
        <p style="padding-left: 1em">
          <code>Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException:
-1<br />
  at net.sf.saxon.om.Chain.itemAt(Chain.java:161)<br />
  at net.sf.saxon.om.SequenceTool.itemAt(SequenceTool.java:130)<br />
  at net.sf.saxon.expr.FilterExpression.iterate(FilterExpression.java:1143)<br />
  at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:365)<br />
  at net.sf.saxon.expr.instruct.BlockIterator.next(BlockIterator.java:49)<br />
  at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:70)<br />
  at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:264)<br />
  at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:660)<br />
  at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:239)<br />
  at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1057)<br />
  at net.sf.saxon.Controller.transformDocument(Controller.java:2088)<br />
  at net.sf.saxon.Controller.transform(Controller.java:1911)<br />
  ...</code>
        </p>
        <p>
The problem is reported at: <a href="https://saxonica.plan.io/boards/3/topics/5986">Exception
during execution in Saxon-HE-9.5.1-6</a> and also tracked at <a href="https://saxonica.plan.io/issues/2104">https://saxonica.plan.io/issues/2104</a>.
</p>
        <p>
          <b>Update:</b> according to Michael Kay the issue is fixed. See <a href="https://saxonica.plan.io/issues/2104#note-4">note
#4</a>:
</p>
        <p style="padding-left: 1em">
          <i>I have committed a patch to Chain.itemAt() on the 9.5 and 9.6 branches to check
for index&lt;0</i>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c3178b61-8e62-4ae7-b00a-4ebde095b3ef" />
      </body>
      <title>Exception during execution in Saxon-HE-9.5.1-6</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c3178b61-8e62-4ae7-b00a-4ebde095b3ef.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2014/07/14/ExceptionDuringExecutionInSaxonHE9516.aspx</link>
      <pubDate>Mon, 14 Jul 2014 08:08:01 GMT</pubDate>
      <description>&lt;p&gt;
These days we're not active xslt developers, though we still consider xslt and xquery
are important part of our personal experience and self education.
&lt;/p&gt;
&lt;p&gt;
Besides, we have a pretty large xslt code base that is and will be in use. We think
xslt/xquery is in use in many other big and small projects thus they have a strong
position as a niche languages.
&lt;/p&gt;
&lt;p&gt;
Thus we think it's important to help to those who support xslt/xquery engines. That's
what we're regularly doing (thanks to our code base). 
&lt;/p&gt;
&lt;p&gt;
Now, to the problem we just have found. Please consider the code:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;xsl:stylesheet version="2.0"&lt;br /&gt;
&amp;nbsp; xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform"&gt;http://www.w3.org/1999/XSL/Transform&lt;/a&gt;" 
&lt;br /&gt;
&amp;nbsp; xmlns:xs="&lt;a href="http://www.w3.org/2001/XMLSchema"&gt;http://www.w3.org/2001/XMLSchema&lt;/a&gt;" 
&lt;br /&gt;
&amp;nbsp; xmlns:t="this"&lt;br /&gt;
&amp;nbsp; exclude-result-prefixes="xs t"&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:template match="/"&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:param name="new-line-text" as="xs:string" select="'&amp;#10;'"/&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:variable name="items" as="item()*" select="'select', $new-line-text"/&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:message select="t:string-join($items)"/&gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xsl:template&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp; &amp;lt;!--&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; Joins adjacent string items.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $items - items to join.&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Returns joined items.&lt;br /&gt;
&amp;nbsp; --&gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;xsl:function name="t:string-join" as="item()*"&gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:param name="items" as="item()*"/&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:variable name="indices" as="xs:integer*" select="&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 0,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; index-of&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for $item in $items return&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $item instance
of xs:string&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; false()&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; count($items) + 1"/&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xsl:sequence select="&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; for $i in 1 to count($indices) - 1 return&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $items[$indices[$i]],&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string-join&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; subsequence&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $items,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $indices[$i] +
1,&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; $indices[$i + 1]
- $indices[$i] - 1&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ),&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ''&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; )"/&gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xsl:function&gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The output is:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code &gt;Exception in thread &amp;quot;main&amp;quot; java.lang.ArrayIndexOutOfBoundsException:
-1&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.om.Chain.itemAt(Chain.java:161)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.om.SequenceTool.itemAt(SequenceTool.java:130)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.FilterExpression.iterate(FilterExpression.java:1143)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.LetExpression.iterate(LetExpression.java:365)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.instruct.BlockIterator.next(BlockIterator.java:49)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.MappingIterator.next(MappingIterator.java:70)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:264)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:660)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.expr.instruct.Template.applyLeavingTail(Template.java:239)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:1057)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.Controller.transformDocument(Controller.java:2088)&lt;br /&gt;
&amp;nbsp; at net.sf.saxon.Controller.transform(Controller.java:1911)&lt;br /&gt;
&amp;nbsp; ...&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The problem is reported at: &lt;a href="https://saxonica.plan.io/boards/3/topics/5986"&gt;Exception
during execution in Saxon-HE-9.5.1-6&lt;/a&gt; and also tracked at &lt;a href="https://saxonica.plan.io/issues/2104"&gt;https://saxonica.plan.io/issues/2104&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; according to Michael Kay the issue is fixed. See &lt;a href="https://saxonica.plan.io/issues/2104#note-4"&gt;note
#4&lt;/a&gt;:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;i&gt;I have committed a patch to Chain.itemAt() on the 9.5 and 9.6 branches to check
for index&amp;lt;0&lt;/i&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c3178b61-8e62-4ae7-b00a-4ebde095b3ef" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c3178b61-8e62-4ae7-b00a-4ebde095b3ef.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=7454f916-e128-48bb-a274-b9a7b00a22da</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7454f916-e128-48bb-a274-b9a7b00a22da.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7454f916-e128-48bb-a274-b9a7b00a22da.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=7454f916-e128-48bb-a274-b9a7b00a22da</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Among proposed new features (other than <a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-maps">Maps</a> and <a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-arrays">Arrays</a>)
in <a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/">XPath 3.1</a> we like <a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-arrow-operator">Arrow
operator (=&gt;)</a>. 
</p>
        <p>
It's defined like this: 
</p>
        <div style="padding-left: 1em; font-style: italic">
          <p>
[<a>Definition</a>: An <b>arrow operator</b> is a postfix operator that applies a
function to an item, using the item as the first argument to the function.] If <code>$i</code> is
an item and <code>f()</code> is a function, then <code>$i=&gt;f()</code> is equivalent
to <code>f($i)</code>, and <code>$i=&gt;f($j)</code> is equivalent to <code>f($i,
$j)</code>. 
</p>
          <p>
This syntax is particularly helpful when conventional function call syntax is unreadable,
e.g. when applying multiple functions to an item. For instance, the following expression
is difficult to read due to the nesting of parentheses, and invites syntax errors
due to unbalanced parentheses: 
</p>
          <div>
            <pre>tokenize((normalize-unicode(upper-case($string))),"\s+")</pre>
          </div>
          <p>
Many people consider the following expression easier to read, and it is much easier
to see that the parentheses are balanced: 
</p>
          <div>
            <pre>$string=&gt;upper-case()=&gt;normalize-unicode()=&gt;tokenize("\s+")</pre>
          </div>
        </div>
        <p>
 What it looks like?
</p>
        <p>
Right! It's like extension functions in C#.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7454f916-e128-48bb-a274-b9a7b00a22da" />
      </body>
      <title>New features in XPath 3.1</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,7454f916-e128-48bb-a274-b9a7b00a22da.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2014/04/28/NewFeaturesInXPath31.aspx</link>
      <pubDate>Mon, 28 Apr 2014 06:20:27 GMT</pubDate>
      <description>&lt;p&gt;
Among proposed new features (other than &lt;a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-maps"&gt;Maps&lt;/a&gt; and &lt;a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-arrays"&gt;Arrays&lt;/a&gt;)
in &lt;a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/"&gt;XPath 3.1&lt;/a&gt; we like &lt;a href="http://www.w3.org/TR/2014/WD-xpath-31-20140424/#id-arrow-operator"&gt;Arrow
operator (=&amp;gt;)&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
It&amp;#39;s defined like this: 
&lt;/p&gt;
&lt;div style="padding-left: 1em; font-style: italic"&gt;
&lt;p&gt;
[&lt;a&gt;Definition&lt;/a&gt;: An &lt;b&gt;arrow operator&lt;/b&gt; is a postfix operator that applies a
function to an item, using the item as the first argument to the function.] If &lt;code&gt;$i&lt;/code&gt; is
an item and &lt;code&gt;f()&lt;/code&gt; is a function, then &lt;code&gt;$i=&amp;gt;f()&lt;/code&gt; is equivalent
to &lt;code&gt;f($i)&lt;/code&gt;, and &lt;code&gt;$i=&amp;gt;f($j)&lt;/code&gt; is equivalent to &lt;code&gt;f($i,
$j)&lt;/code&gt;. 
&lt;/p&gt;
&lt;p&gt;
This syntax is particularly helpful when conventional function call syntax is unreadable,
e.g. when applying multiple functions to an item. For instance, the following expression
is difficult to read due to the nesting of parentheses, and invites syntax errors
due to unbalanced parentheses: 
&lt;/p&gt;
&lt;div&gt;
&lt;pre&gt;tokenize((normalize-unicode(upper-case($string))),&amp;quot;\s+&amp;quot;)&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Many people consider the following expression easier to read, and it is much easier
to see that the parentheses are balanced: 
&lt;/p&gt;
&lt;div&gt;
&lt;pre&gt;$string=&amp;gt;upper-case()=&amp;gt;normalize-unicode()=&amp;gt;tokenize(&amp;quot;\s+&amp;quot;)&lt;/pre&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;
&amp;nbsp;What it looks like?
&lt;/p&gt;
&lt;p&gt;
Right! It&amp;#39;s like extension functions in C#.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=7454f916-e128-48bb-a274-b9a7b00a22da" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,7454f916-e128-48bb-a274-b9a7b00a22da.aspx</comments>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9dde3b91-d5ff-4ba3-b615-a28b9f496175</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9dde3b91-d5ff-4ba3-b615-a28b9f496175.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9dde3b91-d5ff-4ba3-b615-a28b9f496175.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9dde3b91-d5ff-4ba3-b615-a28b9f496175</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Awhile ago we have created a set of xml schemas and xslt to represent different languages
as xml, and to generate source from those xmls. This way we know to represent and
generate: java, c#, cobol, and several sql dialects (read about languages xom on this
site).
</p>
        <p>
Here, we'd like to expose a nuisance we had with sql dialects schema.
</p>
        <p>
Our goal was to define a basic sql schema, and dialect extensions. This way we assumed
to express general and dialect specific constructs. So, lets consider an example.
</p>
        <p>
General:
</p>
        <p style="padding-left: 1em">
          <code>-- Select one row<br />
select * from A</code>
        </p>
        <p>
DB2:
</p>
        <p style="padding-left: 1em">
          <code>select * from A fetch first row only</code>
        </p>
        <p>
T-SQL:
</p>
        <p style="padding-left: 1em">
          <code>select top 1 * from A</code>
        </p>
        <p>
Oracle:
</p>
        <p style="padding-left: 1em">
          <code>select * from A where rownum = 1</code>
        </p>
        <p>
All these queries have common core syntax, while at the same time have dialect specific
means to express intention to return first row only.
</p>
        <p>
Down to the xml schema basic select statement looks like this:
</p>
        <p style="padding-left: 1em">
          <code> &lt;xs:complexType name="select-statement"&gt;<br />
  &lt;xs:complexContent&gt;<br />
    &lt;xs:extension base="full-select-statement"&gt;<br />
      &lt;xs:sequence&gt;<br />
        &lt;xs:element name="columns" type="columns-clause"&gt;<br />
        &lt;xs:element name="from" type="from-clause"
minOccurs="0"&gt;<br />
        &lt;xs:element name="where" type="unary-expression"
minOccurs="0"/&gt;<br />
        &lt;xs:element name="group-by" type="expression-list"
minOccurs="0"/&gt;<br />
        &lt;xs:element name="having" type="unary-expression"
minOccurs="0"/&gt;<br />
        &lt;xs:element name="order-by" type="order-by-clause"
minOccurs="0"/&gt;<br />
      &lt;/xs:sequence&gt;<br />
      &lt;xs:attribute name="specification" type="query-specification"<br />
        use="optional" default="all"/&gt;<br />
    &lt;/xs:extension&gt;<br />
  &lt;/xs:complexContent&gt;<br />
&lt;/xs:complexType&gt; </code>
        </p>
        <p>
Here all is relatively clear. The generic select looks like:
</p>
        <p style="padding-left: 1em">
          <code>&lt;sql:select&gt;<br />
  &lt;sql:columns&gt;<br />
    &lt;sql:column wildcard="true"/&gt;<br />
  &lt;/sql:columns&gt;<br />
  &lt;sql:from&gt;<br />
    &lt;sql:table name="A"/&gt;<br />
  &lt;/sql:from&gt;<br />
&lt;/sql:select&gt;</code>
        </p>
        <p>
But how would you define dialect specifics?
</p>
        <p>
E.g. for T-SQL we would like to see a markup:
</p>
        <p style="padding-left: 1em">
          <code>&lt;sql:select&gt;<br />
  &lt;tsql:top&gt;<br />
    &lt;sql:number value="1"/&gt;<br />
  &lt;/tsql:top&gt;<br />
  &lt;sql:columns&gt;<br />
    &lt;sql:column wildcard="true"/&gt;<br />
  &lt;/sql:columns&gt;<br />
  &lt;sql:from&gt;<br />
    &lt;sql:table name="A"/&gt;<br />
  &lt;/sql:from&gt;<br />
&lt;/sql:select&gt;</code>
        </p>
        <p>
While for DB2 there should be:
</p>
        <p style="padding-left: 1em">
          <code>&lt;sql:select&gt;<br />
  &lt;sql:columns&gt;<br />
    &lt;sql:column wildcard="true"/&gt;<br />
  &lt;/sql:columns&gt;<br />
  &lt;sql:from&gt;<br />
    &lt;sql:table name="A"/&gt;<br />
  &lt;/sql:from&gt;<br />
  &lt;db2:fetch-first rows="1"/&gt;<br />
&lt;/sql:select&gt;</code>
        </p>
        <p>
So, again the quesions are:
</p>
        <ul>
          <li>
how to define basic sql schema with goal to extend it in direction of DB2 or T-SQL?</li>
          <li>
how to define an xslt sql serializer that will be also extendable?</li>
        </ul>
        <p>
Though we have tried several solutions to that problem, none is satisfactory enough.
To allow extensions we have defined that all elements in sql schema are based on <code>sql-element</code>,
which allows extensions:
</p>
        <p style="padding-left: 1em">
          <code> &lt;xs:complexType name="sql-element" abstract="true"&gt;<br />
  &lt;xs:sequence&gt; 
<br />
    &lt;xs:element ref="extension" minOccurs="0" maxOccurs="unbounded"/&gt;<br />
  &lt;/xs:sequence&gt; 
<br />
&lt;/xs:complexType&gt; 
<br /><br />
&lt;xs:element name="extension" type="extension"/&gt; 
<br /><br />
&lt;xs:complexType name="extension" abstract="true"&gt; 
<br />
  &lt;xs:complexContent&gt; 
<br />
    &lt;xs:extension base="sql-element"/&gt; 
<br />
  &lt;/xs:complexContent&gt; 
<br />
&lt;/xs:complexType&gt; 
<br /><br />
... 
<br /><br />
&lt;xs:element name="top" type="top-extension" substitutionGroup="sql:extension"/&gt;<br /><br />
&lt;xs:complexType name="top-extension"&gt; 
<br />
  &lt;xs:complexContent&gt; 
<br />
    &lt;xs:extension base="sql:extension"&gt; 
<br />
      &lt;xs:sequence&gt; 
<br />
        &lt;xs:element ref="sql:expression"/&gt; 
<br />
      &lt;/xs:sequence&gt; 
<br />
      &lt;xs:attribute name="percent" type="xs:boolean" use="optional"
default="false"/&gt; 
<br />
    &lt;/xs:extension&gt; 
<br />
  &lt;/xs:complexContent&gt; 
<br />
&lt;/xs:complexType&gt; </code>
        </p>
        <p>
Unfortunately, this creates too weak typed schema for extensions, thus intellisence
suggests too many options.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9dde3b91-d5ff-4ba3-b615-a28b9f496175" />
      </body>
      <title>Derived xml schemas</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9dde3b91-d5ff-4ba3-b615-a28b9f496175.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2013/07/03/DerivedXmlSchemas.aspx</link>
      <pubDate>Wed, 03 Jul 2013 05:50:43 GMT</pubDate>
      <description>&lt;p&gt;
Awhile ago we have created a set of xml schemas and xslt to represent different languages
as xml, and to generate source from those xmls. This way we know to represent and
generate: java, c#, cobol, and several sql dialects (read about languages xom on this
site).
&lt;/p&gt;
&lt;p&gt;
Here, we&amp;#39;d like to expose a nuisance we had with sql dialects schema.
&lt;/p&gt;
&lt;p&gt;
Our goal was to define a basic sql schema, and dialect extensions. This way we assumed
to express general and dialect specific constructs. So, lets consider an example.
&lt;/p&gt;
&lt;p&gt;
General:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;-- Select one row&lt;br /&gt;
select * from A&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
DB2:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;select * from A fetch first row only&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
T-SQL:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;select top 1 * from A&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Oracle:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;select * from A where rownum = 1&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
All these queries have common core syntax, while at the same time have dialect specific
means to express intention to return first row only.
&lt;/p&gt;
&lt;p&gt;
Down to the xml schema basic select statement looks like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;xs:complexType name="select-statement"&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;xs:complexContent&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:extension base="full-select-statement"&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:sequence&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="columns" type=&amp;quot;columns-clause&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="from" type=&amp;quot;from-clause&amp;quot;
minOccurs=&amp;quot;0&amp;quot;&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="where" type="unary-expression"
minOccurs="0"/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="group-by" type="expression-list"
minOccurs="0"/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="having" type="unary-expression"
minOccurs="0"/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element name="order-by" type="order-by-clause"
minOccurs="0"/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:sequence&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:attribute name="specification" type="query-specification"&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; use="optional" default="all"/&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:extension&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xs:complexContent&amp;gt;&lt;br /&gt;
&amp;lt;/xs:complexType&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Here all is relatively clear. The generic select looks like:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;sql:select&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:column wildcard=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:from&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:table name=&amp;quot;A&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:from&amp;gt;&lt;br /&gt;
&amp;lt;/sql:select&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
But how would you define dialect specifics?
&lt;/p&gt;
&lt;p&gt;
E.g. for T-SQL we would like to see a markup:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;sql:select&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;tsql:top&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:number value=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/tsql:top&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:column wildcard=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:from&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:table name=&amp;quot;A&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:from&amp;gt;&lt;br /&gt;
&amp;lt;/sql:select&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
While for DB2 there should be:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;sql:select&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:column wildcard=&amp;quot;true&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:columns&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;sql:from&amp;gt;&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;sql:table name=&amp;quot;A&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/sql:from&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;db2:fetch-first rows=&amp;quot;1&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;lt;/sql:select&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
So, again the quesions are:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
how to define basic sql schema with goal to extend it in direction of DB2 or T-SQL?&lt;/li&gt;
&lt;li&gt;
how to define an xslt sql serializer that will be also extendable?&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Though we have tried several solutions to that problem, none is satisfactory enough.
To allow extensions we have defined that all elements in sql schema are based on &lt;code&gt;sql-element&lt;/code&gt;,
which allows extensions:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; &amp;lt;xs:complexType name="sql-element" abstract="true"&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;xs:sequence&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element ref="extension" minOccurs=&amp;quot;0&amp;quot; maxOccurs=&amp;quot;unbounded&amp;quot;/&amp;gt;&lt;br /&gt;
&amp;nbsp; &amp;lt;/xs:sequence&amp;gt; 
&lt;br /&gt;
&amp;lt;/xs:complexType&amp;gt; 
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xs:element name="extension" type="extension"/&amp;gt; 
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xs:complexType name="extension" abstract="true"&amp;gt; 
&lt;br /&gt;
&amp;nbsp; &amp;lt;xs:complexContent&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:extension base="sql-element"/&amp;gt; 
&lt;br /&gt;
&amp;nbsp; &amp;lt;/xs:complexContent&amp;gt; 
&lt;br /&gt;
&amp;lt;/xs:complexType&amp;gt; 
&lt;br /&gt;
&lt;br /&gt;
... 
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xs:element name="top" type="top-extension" substitutionGroup="sql:extension"/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xs:complexType name="top-extension"&amp;gt; 
&lt;br /&gt;
&amp;nbsp; &amp;lt;xs:complexContent&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:extension base="sql:extension"&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:sequence&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:element ref="sql:expression"/&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:sequence&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;xs:attribute name="percent" type="xs:boolean" use="optional"
default="false"/&amp;gt; 
&lt;br /&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/xs:extension&amp;gt; 
&lt;br /&gt;
&amp;nbsp; &amp;lt;/xs:complexContent&amp;gt; 
&lt;br /&gt;
&amp;lt;/xs:complexType&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Unfortunately, this creates too weak typed schema for extensions, thus intellisence
suggests too many options.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9dde3b91-d5ff-4ba3-b615-a28b9f496175" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9dde3b91-d5ff-4ba3-b615-a28b9f496175.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=98b58257-9069-4d13-9d10-a7061e14e834</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</pingback:target>
      <dc:creator>Arthur Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=98b58257-9069-4d13-9d10-a7061e14e834</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you deal with web applications you probably have already dealt with export data
to Excel. There are several options to prepare data for Excel:
</p>
        <ul>
          <li>
generate CSV;</li>
          <li>
generate HTML that excel understands;</li>
          <li>
generate XML in Spreadsheet 2003 format;</li>
          <li>
generate data using Open XML SDK or some other 3rd party libraries;</li>
          <li>
generate data in XLSX format, according to Open XML specification.</li>
        </ul>
        <p>
You may find a good article with pros and cons of each solution <a href="http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx" target="_blank">here</a>.
We, in our turn, would like to share our experience in this field. Let's start from
requirements:
</p>
        <ul>
          <li>
Often we have to export huge data-sets.</li>
          <li>
We should be able to format, parametrize and to apply different styles to the exported
data.</li>
          <li>
There are cases when exported data may contain more than one table per sheet or even
more than one sheet.</li>
          <li>
Some exported data have to be illustrated with charts.</li>
        </ul>
        <p>
All these requirements led us to a solution based on XSLT processing of streamed data.
The advantage of this solution is that the result is immediately forwarded to a client
as fast as XSLT starts to generate output. Such approach is much productive than generating
of XLSX using of Open XML SDK or any other third party library, since it avoids keeping
a huge data-sets in memory on the server side.
</p>
        <p style="direction: ltr">
Another advantage - is simple maintenance, as we achieve clear separation of data
and presentation layers. On each request to change formatting or apply another style
to a cell you just have to modify xslt file(s) that generate variable parts of XLSX.
</p>
        <p>
As result, our clients get XLSX files according with Open XML specifications. The
details of implementations of our solution see in our next posts.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834" />
      </body>
      <title>Export data to Excel</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/10/29/ExportDataToExcel.aspx</link>
      <pubDate>Mon, 29 Oct 2012 15:34:38 GMT</pubDate>
      <description>&lt;p&gt;
If you deal with web applications you probably have already dealt with export data
to Excel. There are several options to prepare data for Excel:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
generate CSV;&lt;/li&gt;
&lt;li&gt;
generate HTML that excel understands;&lt;/li&gt;
&lt;li&gt;
generate XML in Spreadsheet 2003 format;&lt;/li&gt;
&lt;li&gt;
generate data using Open XML SDK or some other 3rd party libraries;&lt;/li&gt;
&lt;li&gt;
generate data in XLSX format, according to Open XML specification.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
You may find a good article with pros and cons of each solution &lt;a href="http://blogs.msdn.com/b/erikaehrli/archive/2009/01/30/how-to-export-data-to-excel-from-an-asp-net-application-avoid-the-file-format-differ-prompt.aspx" target="_blank"&gt;here&lt;/a&gt;.
We, in our turn, would like to share our experience in this field. Let's start from
requirements:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Often we have to export huge data-sets.&lt;/li&gt;
&lt;li&gt;
We should be able to format, parametrize and to apply different styles to the exported
data.&lt;/li&gt;
&lt;li&gt;
There are cases when exported data may contain more than one table per sheet or even
more than one sheet.&lt;/li&gt;
&lt;li&gt;
Some exported data have to be illustrated with charts.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
All these requirements led us to a solution based on XSLT processing of streamed data.
The advantage of this solution is that the result is immediately forwarded to a client
as fast as XSLT starts to generate output. Such approach is much productive than generating
of XLSX using of Open XML SDK or any other third party library, since it avoids keeping
a huge data-sets in memory on the server side.
&lt;/p&gt;
&lt;p style="direction: ltr"&gt;
Another advantage - is simple maintenance, as we achieve clear separation of data
and presentation layers. On each request to change formatting or apply another style
to a cell you just have to modify xslt file(s) that generate variable parts of XLSX.
&lt;/p&gt;
&lt;p&gt;
As result, our clients get XLSX files according with Open XML specifications. The
details of implementations of our solution see in our next posts.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=98b58257-9069-4d13-9d10-a7061e14e834" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,98b58257-9069-4d13-9d10-a7061e14e834.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=cad54317-1876-4b98-a8d2-7e44e5dda1f7</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=cad54317-1876-4b98-a8d2-7e44e5dda1f7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier we have shown <a href="http://www.nesterovsky-bros.com/weblog/2012/07/22/StreamingEntityData.aspx"> how
to build streaming xml reader from business data</a> and have reminded about <a href="http://www.nesterovsky-bros.com/weblog/2012/07/26/StreamingXsltTransformationWithForwardXPathNavigator.aspx">ForwardXPathNavigator
which helps to create a streaming xslt transformation</a>. Now we want to show how
to stream content produced with xslt out of WCF service.
</p>
        <p>
To achieve streaming in WCF one needs: 
</p>
        <p>
1. To configure service to use streaming. Description on how to do this can be found
in the internet. See web.config of the sample <a href="http://www.nesterovsky-bros.com/download/Streaming.zip"> Streaming.zip</a> for
the details.
</p>
        <p>
2. Create a service with a method returning <code>Stream</code>:
</p>
        <p>
          <code>[ServiceContract(Namespace = "http://www.nesterovsky-bros.com")]<br />
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]<br />
public class Service<br />
{<br />
[OperationContract]<br />
[WebGet(RequestFormat = WebMessageFormat.Json)]<br />
public Stream GetPeopleHtml(int count, int seed)<br />
{<br />
...<br />
}<br />
}</code>
        </p>
        <p>
2. Return a <code>Stream</code> from xsl transformation. 
</p>
        <p>
Unfortunately (we mentioned it already), <code>XslCompiledTransform</code> generates
its output into <code>XmlWriter</code> (or into output <code>Stream</code>) rather
than exposes result as <code>XmlReader</code>, while WCF gets input stream and passes
it to a client. 
</p>
        <p>
We could generate xslt output into a file or a memory <code>Stream</code> and then
return that content as input <code>Stream</code>, but this will defeat a goal of streaming,
as client would have started to get data no earlier that the xslt completed its work.
What we need instead is a pipe that form xslt output <code>Stream</code> to an input <code>Stream</code> returned
from WCF.
</p>
        <p>
.NET implements pipe streams, so our task is trivial. We have defined a utility method
that creates an input <code>Stream</code> from a generator populating an output <code>Stream</code>:
</p>
        <p>
          <code> public static Stream GetPipedStream(Action&lt;Stream&gt; generator)<br />
{<br />
var output = new AnonymousPipeServerStream();<br />
var input = new AnonymousPipeClientStream(<br />
output.GetClientHandleAsString());<br /><br />
Task.Factory.StartNew(<br />
() =&gt;<br />
{<br />
using(output)<br />
{<br />
generator(output);<br />
output.WaitForPipeDrain();<br />
}<br />
},<br />
TaskCreationOptions.LongRunning);<br /><br />
return input;<br />
} </code>
        </p>
        <p>
We wrapped xsl transformation as such a generator:
</p>
        <p>
          <code>[OperationContract]<br />
[WebGet(RequestFormat = WebMessageFormat.Json)]<br />
public Stream GetPeopleHtml(int count, int seed)<br />
{<br />
var context = WebOperationContext.Current;<br /><br />
context.OutgoingResponse.ContentType = "text/html";<br />
context.OutgoingResponse.Headers["Content-Disposition"] = 
<br />
"attachment;filename=reports.html";<br /><br />
var cache = HttpRuntime.Cache;<br />
var path = HttpContext.Current.Server.MapPath("~/People.xslt");<br />
var transform = cache[path] as XslCompiledTransform;<br /><br />
if (transform == null)<br />
{<br />
transform = new XslCompiledTransform();<br />
transform.Load(path);<br />
cache.Insert(path, transform, new CacheDependency(path));<br />
}<br /><br />
return Extensions.<strong>GetPipedStream</strong>(<br />
output =&gt;<br />
{<br />
// We have a streamed business data.<br />
var people = Data.CreateRandomData(count, seed, 0, count);<br /><br />
// We want to see it as streamed xml data.<br />
using(var stream =<br />
people.<strong>ToXmlStream</strong>("people", "http://www.nesterovsky-bros.com"))<br />
using(var reader = XmlReader.Create(stream))<br />
{<br />
// XPath forward navigator is used as an input source.<br />
transform.Transform(<br />
new <strong>ForwardXPathNavigator</strong>(reader),<br />
new XsltArgumentList(),<br />
output);<br />
}<br />
});<br />
}</code>
        </p>
        <p>
This way we have build a code that streams data directly from business data to a client
in a form of report. A set of utility functions and classes helped us to overcome
.NET's limitations and to build simple code that one can easily support.
</p>
        <p>
The sources can be found at <a href="http://www.nesterovsky-bros.com/download/Streaming.zip"> Streaming.zip</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7" />
      </body>
      <title>Stream xslt transformation through WCF</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/08/03/StreamXsltTransformationThroughWCF.aspx</link>
      <pubDate>Fri, 03 Aug 2012 22:32:49 GMT</pubDate>
      <description>  &lt;p&gt;
Earlier we have shown &lt;a href="http://www.nesterovsky-bros.com/weblog/2012/07/22/StreamingEntityData.aspx"&gt; how
to build streaming xml reader from business data&lt;/a&gt; and have reminded about &lt;a href="http://www.nesterovsky-bros.com/weblog/2012/07/26/StreamingXsltTransformationWithForwardXPathNavigator.aspx"&gt;ForwardXPathNavigator
which helps to create a streaming xslt transformation&lt;/a&gt;. Now we want to show how
to stream content produced with xslt out of WCF service.
&lt;/p&gt;
&lt;p&gt;
To achieve streaming in WCF one needs: 
&lt;/p&gt;
&lt;p&gt;
1. To configure service to use streaming. Description on how to do this can be found
in the internet. See web.config of the sample &lt;a href="http://www.nesterovsky-bros.com/download/Streaming.zip"&gt; Streaming.zip&lt;/a&gt; for
the details.
&lt;/p&gt;
&lt;p&gt;
2. Create a service with a method returning &lt;code&gt;Stream&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;[ServiceContract(Namespace = "http://www.nesterovsky-bros.com")]&lt;br /&gt;
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]&lt;br /&gt;
public class Service&lt;br /&gt;
{&lt;br /&gt;
[OperationContract]&lt;br /&gt;
[WebGet(RequestFormat = WebMessageFormat.Json)]&lt;br /&gt;
public Stream GetPeopleHtml(int count, int seed)&lt;br /&gt;
{&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
2. Return a &lt;code&gt;Stream&lt;/code&gt; from xsl transformation. 
&lt;/p&gt;
&lt;p&gt;
Unfortunately (we mentioned it already), &lt;code&gt;XslCompiledTransform&lt;/code&gt; generates
its output into &lt;code&gt;XmlWriter&lt;/code&gt; (or into output &lt;code&gt;Stream&lt;/code&gt;) rather
than exposes result as &lt;code&gt;XmlReader&lt;/code&gt;, while WCF gets input stream and passes
it to a client. 
&lt;/p&gt;
&lt;p&gt;
We could generate xslt output into a file or a memory &lt;code&gt;Stream&lt;/code&gt; and then
return that content as input &lt;code&gt;Stream&lt;/code&gt;, but this will defeat a goal of streaming,
as client would have started to get data no earlier that the xslt completed its work.
What we need instead is a pipe that form xslt output &lt;code&gt;Stream&lt;/code&gt; to an input &lt;code&gt;Stream&lt;/code&gt; returned
from WCF.
&lt;/p&gt;
&lt;p&gt;
.NET implements pipe streams, so our task is trivial. We have defined a utility method
that creates an input &lt;code&gt;Stream&lt;/code&gt; from a generator populating an output &lt;code&gt;Stream&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; public static Stream GetPipedStream(Action&amp;lt;Stream&amp;gt; generator)&lt;br /&gt;
{&lt;br /&gt;
var output = new AnonymousPipeServerStream();&lt;br /&gt;
var input = new AnonymousPipeClientStream(&lt;br /&gt;
output.GetClientHandleAsString());&lt;br /&gt;
&lt;br /&gt;
Task.Factory.StartNew(&lt;br /&gt;
() =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
using(output)&lt;br /&gt;
{&lt;br /&gt;
generator(output);&lt;br /&gt;
output.WaitForPipeDrain();&lt;br /&gt;
}&lt;br /&gt;
},&lt;br /&gt;
TaskCreationOptions.LongRunning);&lt;br /&gt;
&lt;br /&gt;
return input;&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
We wrapped xsl transformation as such a generator:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;[OperationContract]&lt;br /&gt;
[WebGet(RequestFormat = WebMessageFormat.Json)]&lt;br /&gt;
public Stream GetPeopleHtml(int count, int seed)&lt;br /&gt;
{&lt;br /&gt;
var context = WebOperationContext.Current;&lt;br /&gt;
&lt;br /&gt;
context.OutgoingResponse.ContentType = "text/html";&lt;br /&gt;
context.OutgoingResponse.Headers["Content-Disposition"] = 
&lt;br /&gt;
"attachment;filename=reports.html";&lt;br /&gt;
&lt;br /&gt;
var cache = HttpRuntime.Cache;&lt;br /&gt;
var path = HttpContext.Current.Server.MapPath("~/People.xslt");&lt;br /&gt;
var transform = cache[path] as XslCompiledTransform;&lt;br /&gt;
&lt;br /&gt;
if (transform == null)&lt;br /&gt;
{&lt;br /&gt;
transform = new XslCompiledTransform();&lt;br /&gt;
transform.Load(path);&lt;br /&gt;
cache.Insert(path, transform, new CacheDependency(path));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return Extensions.&lt;strong&gt;GetPipedStream&lt;/strong&gt;(&lt;br /&gt;
output =&amp;gt;&lt;br /&gt;
{&lt;br /&gt;
// We have a streamed business data.&lt;br /&gt;
var people = Data.CreateRandomData(count, seed, 0, count);&lt;br /&gt;
&lt;br /&gt;
// We want to see it as streamed xml data.&lt;br /&gt;
using(var stream =&lt;br /&gt;
people.&lt;strong&gt;ToXmlStream&lt;/strong&gt;("people", "http://www.nesterovsky-bros.com"))&lt;br /&gt;
using(var reader = XmlReader.Create(stream))&lt;br /&gt;
{&lt;br /&gt;
// XPath forward navigator is used as an input source.&lt;br /&gt;
transform.Transform(&lt;br /&gt;
new &lt;strong&gt;ForwardXPathNavigator&lt;/strong&gt;(reader),&lt;br /&gt;
new XsltArgumentList(),&lt;br /&gt;
output);&lt;br /&gt;
}&lt;br /&gt;
});&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This way we have build a code that streams data directly from business data to a client
in a form of report. A set of utility functions and classes helped us to overcome
.NET&amp;#39;s limitations and to build simple code that one can easily support.
&lt;/p&gt;
&lt;p&gt;
The sources can be found at &lt;a href="http://www.nesterovsky-bros.com/download/Streaming.zip"&gt; Streaming.zip&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=cad54317-1876-4b98-a8d2-7e44e5dda1f7" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,cad54317-1876-4b98-a8d2-7e44e5dda1f7.aspx</comments>
      <category>.NET</category>
      <category>ASP.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=24094700-ca7e-4e73-8b30-fbdc9d72072a</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,24094700-ca7e-4e73-8b30-fbdc9d72072a.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,24094700-ca7e-4e73-8b30-fbdc9d72072a.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=24094700-ca7e-4e73-8b30-fbdc9d72072a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
In the previous <a href="http://www.nesterovsky-bros.com/weblog/2012/07/22/StreamingEntityData.aspx"> post
about streaming</a> we have dropped at the point where we have <code>XmlReader</code> in
hands, which continously gets data from <code>IEnumerable&lt;Person&gt;</code> source.
Now we shall remind about <code>ForwardXPathNavigator</code> - a class we have built
back in 2002, which adds streaming transformations to .NET's xslt processor.
</p>
        <p>
While <code>XslCompiledTransform</code> is desperately obsolete, and no upgrade will
possibly follow; still it's among the fastest xslt 1.0 processors. With <code> ForwardXPathNavigator</code> we
add ability to transform input data of arbitrary size to this processor.
</p>
        <p>
We find it interesting that <a href="http://www.w3.org/TR/xslt-30/#streaming-concepts"> xslt
3.0 Working Draft defines streaming processing</a> in a way that closely matches rules
for <code>ForwardXPathNavigator</code>:
</p>
        <div style="padding-left: 1em; font-style: italic">
          <p>
Streaming achieves two important objectives: it allows large documents to be transformed
without requiring correspondingly large amounts of memory; and it allows the processor
to start producing output before it has finished receiving its input, thus reducing
latency.
</p>
          <p>
The rules for streamability, which are defined in detail in <i>19.3 Streamability
Analysis</i>, impose two main constraints:
</p>
          <ul>
            <li>
              <p>
The only nodes reachable from the node that is currently being processed are its attributes
and namespaces, its ancestors and their attributes and namespaces, and its descendants
and their attributes and namespaces. The siblings of the node, and the siblings of
its ancestors, are not reachable in the tree, and any attempt to use their values
is a static error. However, constructs (for example, simple forms of <code>xsl:number</code>,
and simple positional patterns) that require knowledge of the number of preceding
elements by name are permitted.
</p>
            </li>
            <li>
              <p>
When processing a given node in the tree, each descendant node can only be visited
once. Essentially this allows two styles of processing: either visit each of the children
once, and then process that child with the same restrictions applied; or process all
the descendants in a single pass, in which case it is not possible while processing
a descendant to make any further downward selection.
</p>
            </li>
          </ul>
        </div>
        <p>
The only significant difference between <code>ForwardXPathNavigator</code> and xlst
3.0 streaming is in that we reported violations of rules for streamability at runtime,
while xslt 3.0 attempts to perform this analysis at compile time.
</p>
        <p>
Here the C# code for the xslt streamed transformation:
</p>
        <p>
          <code> var transform = new XslCompiledTransform();<br /><br />
transform.Load("People.xslt");<br /><br />
// We have a streamed business data.<br />
var people = Data.CreateRandomData(10000, 0, 0, 10000);<br /><br />
// We want to see it as streamed xml data.<br />
using(var stream =<br />
people.ToXmlStream("people", "http://www.nesterovsky-bros.com"))<br />
using(var reader = XmlReader.Create(stream))<br />
using(var output = File.Create("people.html"))<br />
{<br />
// XPath forward navigator is used as an input source.<br />
transform.Transform(<br /><strong>new ForwardXPathNavigator(reader)</strong>,<br />
new XsltArgumentList(),<br />
output);<br />
} </code>
        </p>
        <p>
Notice how <code>XmlReader</code> is wrapped into <code>ForwardXPathNavigator</code>.
</p>
        <p>
To complete the picture we need xslt that follows the streaming rules:
</p>
        <p>
          <code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>"<br />
xmlns:msxsl="urn:schemas-microsoft-com:xslt"<br />
xmlns:d="<a href="http://www.nesterovsky-bros.com">http://www.nesterovsky-bros.com</a>"<br />
exclude-result-prefixes="msxsl d"&gt;<br /><br />
&lt;xsl:output method="html" indent="yes"/&gt;<br /><br />
&lt;!-- Root template processed in the streaming mode. --&gt;<br />
&lt;xsl:template match="/d:people"&gt;<br />
&lt;html&gt;<br />
&lt;head&gt;<br />
&lt;title&gt;List of persons&lt;/title&gt;<br />
&lt;style type="text/css"&gt;<br />
.even<br />
{<br />
}<br /><br />
.odd<br />
{<br />
background: #d0d0d0;<br />
}<br />
&lt;/style&gt;<br />
&lt;/head&gt;<br />
&lt;body&gt;<br />
&lt;table border="1"&gt;<br />
&lt;tr&gt;<br />
&lt;th&gt;ID&lt;/th&gt;<br />
&lt;th&gt;First name&lt;/th&gt;<br />
&lt;th&gt;Last name&lt;/th&gt;<br />
&lt;th&gt;City&lt;/th&gt;<br />
&lt;th&gt;Title&lt;/th&gt;<br />
&lt;th&gt;Age&lt;/th&gt;<br />
&lt;/tr&gt;<br /><br />
&lt;xsl:for-each select="d:person"&gt;<br />
&lt;!-- 
<br />
Get element snapshot.<br />
A snapshot allows arbitrary access to the element's content.<br />
--&gt;<br />
&lt;xsl:variable name="person"&gt;<br />
&lt;xsl:copy-of select="."/&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:variable name="position" select="position()"/&gt;<br /><br />
&lt;xsl:apply-templates mode="snapshot" select="msxsl:node-set($person)/d:person"&gt;<br />
&lt;xsl:with-param name="position" select="$position"/&gt;<br />
&lt;/xsl:apply-templates&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/table&gt;<br />
&lt;/body&gt;<br />
&lt;/html&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;xsl:template mode="snapshot" match="d:person"&gt;<br />
&lt;xsl:param name="position"/&gt;<br /><br />
&lt;tr&gt;<br />
&lt;xsl:attribute name="class"&gt;<br />
&lt;xsl:choose&gt;<br />
&lt;xsl:when test="$position mod 2 = 1"&gt;<br />
&lt;xsl:text&gt;odd&lt;/xsl:text&gt;<br />
&lt;/xsl:when&gt;<br />
&lt;xsl:otherwise&gt;<br />
&lt;xsl:text&gt;even&lt;/xsl:text&gt;<br />
&lt;/xsl:otherwise&gt;<br />
&lt;/xsl:choose&gt;<br />
&lt;/xsl:attribute&gt;<br /><br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:Id"/&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:FirstName"/&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:LastName"/&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:City"/&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:Title"/&gt;<br />
&lt;/td&gt;<br />
&lt;td&gt;<br />
&lt;xsl:value-of select="d:Age"/&gt;<br />
&lt;/td&gt;<br />
&lt;/tr&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;/xsl:stylesheet&gt;</code>
        </p>
        <p>
So, we have started with a streamed entity data, proceeded to the streamed XmlReader
and reached to the streamed xslt transformation.
</p>
        <p>
But at the final post about streaming we shall remind a simple way of building WCF
service returning html stream from our xslt transformation.
</p>
        <p>
The sources can be found at <a href="http://www.nesterovsky-bros.com/download/Streaming.zip"> Streaming.zip</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=24094700-ca7e-4e73-8b30-fbdc9d72072a" />
      </body>
      <title>Streaming xslt transformation with ForwardXPathNavigator</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,24094700-ca7e-4e73-8b30-fbdc9d72072a.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/07/26/StreamingXsltTransformationWithForwardXPathNavigator.aspx</link>
      <pubDate>Thu, 26 Jul 2012 18:49:51 GMT</pubDate>
      <description>&lt;p&gt;
In the previous &lt;a href="http://www.nesterovsky-bros.com/weblog/2012/07/22/StreamingEntityData.aspx"&gt; post
about streaming&lt;/a&gt; we have dropped at the point where we have &lt;code&gt;XmlReader&lt;/code&gt; in
hands, which continously gets data from &lt;code&gt;IEnumerable&amp;lt;Person&amp;gt;&lt;/code&gt; source.
Now we shall remind about &lt;code&gt;ForwardXPathNavigator&lt;/code&gt; - a class we have built
back in 2002, which adds streaming transformations to .NET&amp;#39;s xslt processor.
&lt;/p&gt;
&lt;p&gt;
While &lt;code&gt;XslCompiledTransform&lt;/code&gt; is desperately obsolete, and no upgrade will
possibly follow; still it&amp;#39;s among the fastest xslt 1.0 processors. With &lt;code&gt; ForwardXPathNavigator&lt;/code&gt; we
add ability to transform input data of arbitrary size to this processor.
&lt;/p&gt;
&lt;p&gt;
We find it interesting that &lt;a href="http://www.w3.org/TR/xslt-30/#streaming-concepts"&gt; xslt
3.0 Working Draft defines streaming processing&lt;/a&gt; in a way that closely matches rules
for &lt;code&gt;ForwardXPathNavigator&lt;/code&gt;:
&lt;/p&gt;
&lt;div style="padding-left: 1em; font-style: italic"&gt;
&lt;p&gt;
Streaming achieves two important objectives: it allows large documents to be transformed
without requiring correspondingly large amounts of memory; and it allows the processor
to start producing output before it has finished receiving its input, thus reducing
latency.
&lt;/p&gt;
&lt;p&gt;
The rules for streamability, which are defined in detail in &lt;i&gt;19.3 Streamability
Analysis&lt;/i&gt;, impose two main constraints:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;
The only nodes reachable from the node that is currently being processed are its attributes
and namespaces, its ancestors and their attributes and namespaces, and its descendants
and their attributes and namespaces. The siblings of the node, and the siblings of
its ancestors, are not reachable in the tree, and any attempt to use their values
is a static error. However, constructs (for example, simple forms of &lt;code&gt;xsl:number&lt;/code&gt;,
and simple positional patterns) that require knowledge of the number of preceding
elements by name are permitted.
&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;
When processing a given node in the tree, each descendant node can only be visited
once. Essentially this allows two styles of processing: either visit each of the children
once, and then process that child with the same restrictions applied; or process all
the descendants in a single pass, in which case it is not possible while processing
a descendant to make any further downward selection.
&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
&lt;p&gt;
The only significant difference between &lt;code&gt;ForwardXPathNavigator&lt;/code&gt; and xlst
3.0 streaming is in that we reported violations of rules for streamability at runtime,
while xslt 3.0 attempts to perform this analysis at compile time.
&lt;/p&gt;
&lt;p&gt;
Here the C# code for the xslt streamed transformation:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; var transform = new XslCompiledTransform();&lt;br /&gt;
&lt;br /&gt;
transform.Load("People.xslt");&lt;br /&gt;
&lt;br /&gt;
// We have a streamed business data.&lt;br /&gt;
var people = Data.CreateRandomData(10000, 0, 0, 10000);&lt;br /&gt;
&lt;br /&gt;
// We want to see it as streamed xml data.&lt;br /&gt;
using(var stream =&lt;br /&gt;
people.ToXmlStream("people", "http://www.nesterovsky-bros.com"))&lt;br /&gt;
using(var reader = XmlReader.Create(stream))&lt;br /&gt;
using(var output = File.Create("people.html"))&lt;br /&gt;
{&lt;br /&gt;
// XPath forward navigator is used as an input source.&lt;br /&gt;
transform.Transform(&lt;br /&gt;
&lt;strong&gt;new ForwardXPathNavigator(reader)&lt;/strong&gt;,&lt;br /&gt;
new XsltArgumentList(),&lt;br /&gt;
output);&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Notice how &lt;code&gt;XmlReader&lt;/code&gt; is wrapped into &lt;code&gt;ForwardXPathNavigator&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;
To complete the picture we need xslt that follows the streaming rules:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt;&amp;lt;xsl:stylesheet version="1.0" xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform"&gt;http://www.w3.org/1999/XSL/Transform&lt;/a&gt;"&lt;br /&gt;
xmlns:msxsl="urn:schemas-microsoft-com:xslt"&lt;br /&gt;
xmlns:d="&lt;a href="http://www.nesterovsky-bros.com"&gt;http://www.nesterovsky-bros.com&lt;/a&gt;"&lt;br /&gt;
exclude-result-prefixes="msxsl d"&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:output method="html" indent="yes"/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;!-- Root template processed in the streaming mode. --&amp;gt;&lt;br /&gt;
&amp;lt;xsl:template match="/d:people"&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&lt;br /&gt;
&amp;lt;head&amp;gt;&lt;br /&gt;
&amp;lt;title&amp;gt;List of persons&amp;lt;/title&amp;gt;&lt;br /&gt;
&amp;lt;style type="text/css"&amp;gt;&lt;br /&gt;
.even&lt;br /&gt;
{&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
.odd&lt;br /&gt;
{&lt;br /&gt;
background: #d0d0d0;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/style&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
&amp;lt;table border="1"&amp;gt;&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;ID&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;First name&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Last name&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;City&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;th&amp;gt;Age&amp;lt;/th&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:for-each select="d:person"&amp;gt;&lt;br /&gt;
&amp;lt;!-- 
&lt;br /&gt;
Get element snapshot.&lt;br /&gt;
A snapshot allows arbitrary access to the element&amp;#39;s content.&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name="person"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:copy-of select="."/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name="position" select="position()"/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:apply-templates mode="snapshot" select="msxsl:node-set($person)/d:person"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:with-param name="position" select="$position"/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:apply-templates&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
&amp;lt;/table&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&lt;br /&gt;
&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template mode="snapshot" match="d:person"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:param name="position"/&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;tr&amp;gt;&lt;br /&gt;
&amp;lt;xsl:attribute name="class"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;xsl:when test="$position mod 2 = 1"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:text&amp;gt;odd&amp;lt;/xsl:text&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:when&amp;gt;&lt;br /&gt;
&amp;lt;xsl:otherwise&amp;gt;&lt;br /&gt;
&amp;lt;xsl:text&amp;gt;even&amp;lt;/xsl:text&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:otherwise&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:choose&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:attribute&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:Id"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:FirstName"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:LastName"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:City"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:Title"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;td&amp;gt;&lt;br /&gt;
&amp;lt;xsl:value-of select="d:Age"/&amp;gt;&lt;br /&gt;
&amp;lt;/td&amp;gt;&lt;br /&gt;
&amp;lt;/tr&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
So, we have started with a streamed entity data, proceeded to the streamed XmlReader
and reached to the streamed xslt transformation.
&lt;/p&gt;
&lt;p&gt;
But at the final post about streaming we shall remind a simple way of building WCF
service returning html stream from our xslt transformation.
&lt;/p&gt;
&lt;p&gt;
The sources can be found at &lt;a href="http://www.nesterovsky-bros.com/download/Streaming.zip"&gt; Streaming.zip&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=24094700-ca7e-4e73-8b30-fbdc9d72072a" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,24094700-ca7e-4e73-8b30-fbdc9d72072a.aspx</comments>
      <category>.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=60b3cb37-5da9-4f28-a35f-38d1ef3cccce</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,60b3cb37-5da9-4f28-a35f-38d1ef3cccce.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,60b3cb37-5da9-4f28-a35f-38d1ef3cccce.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=60b3cb37-5da9-4f28-a35f-38d1ef3cccce</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For some reason neither .NET's <code>XmlSerializer</code> nor <code>DataContractSerializer</code> allow
reading data through an <code>XmlReader</code>. These APIs work other way round writing
data into an <code>XmlWriter</code>. To get data through <code>XmlReader</code> one
needs to write it to some destination like a file or memory stream, and then to read
it using <code>XmlReader</code>. This complicates streaming design considerably.
</p>
        <p>
In fact the very same happens with other .NET APIs.
</p>
        <p>
We think the reason of why .NET designers preferred <code>XmlWriter</code> to <code>XmlReader</code> in
those APIs is that <code>XmlReader</code>'s implementation is a state machine
like, while <code>XmlWriter</code>'s implementation looks like a regular procedure.
It's much harder to <strong>manually</strong> write and to support a correct state
machine logic than a procedure.
</p>
        <p>
If history would have gone slightly different way, and if yield return, lambda, and
Enumerator API appeared before <code>XmlReader</code>, and <code>XmlWriter</code> then,
we think, both these classes looked differently. Xml source would have been described
with a <code>IEnumerable&lt;XmlEvent&gt;</code> instead of <code>XmlReader</code>,
and <code>XmlWriter</code> must be looked like a function receiving <code>IEnumerable&lt;XmlEvent&gt;</code>.
Implementing <code>XmlReader</code> would have meant a creating a enumerator. Yield
return and Enumerable API would have helped to implement it in a procedural way.
</p>
        <p>
But in our present we have to deal with the fact that <code>DataContractSerializer</code> should
write the data into <code>XmlWriter</code>, so let's assume we have a project
that uses Entity Framework to access the database, and that you have a data class <code>Person</code>,
and data access method <code>GetPeople()</code>:
</p>
        <p>
          <code> [DataContract(Name = "person", Namespace = "http://www.nesterovsky-bros.com")]<br />
public class Person 
<br />
{ 
<br />
[DataMember] public int Id { get; set; } 
<br />
[DataMember] public string FirstName { get; set; } 
<br />
[DataMember] public string LastName { get; set; } 
<br />
[DataMember] public string City { get; set; } 
<br />
[DataMember] public string Title { get; set; } 
<br />
[DataMember] public DateTime BirthDate { get; set; } 
<br />
[DataMember] public int Age { get; set; } 
<br />
} 
<br /><br />
public static IEnumerable&lt;Person&gt; GetPeople() { ... }</code>
        </p>
        <p>
And your goal is to expose result of <code>GetPeople()</code> as <code>XmlReader</code>.
We achieve result with three simple steps:
</p>
        <ol>
          <li>
Define <code>JoinedStream</code> - an input <code>Stream</code> implementation that
reads data from a enumeration of streams (<code>IEnumerable&lt;Stream&gt;</code>).</li>
          <li>
Build xml parts in the form of <code>IEnumerable&lt;Stream&gt;</code>.</li>
          <li>
Combine parts into final xml stream.</li>
        </ol>
        <p>
The code is rather simple, so here we qoute its essential part:
</p>
        <p>
          <code> public static class Extensions<br />
{<br />
public static Stream JoinStreams(this IEnumerable&lt;Stream&gt; streams, bool closeStreams
= true)<br />
{<br />
return new JoinedStream(streams, closeStreams);<br />
}<br /><br />
public static Stream ToXmlStream&lt;T&gt;(<br />
this IEnumerable&lt;T&gt; items, 
<br />
string rootName = null, 
<br />
string rootNamespace = null)<br />
{<br />
return items.ToXmlStreamParts&lt;T&gt;(rootName, rootNamespace).<br />
JoinStreams(false);<br />
}<br /><br />
private static IEnumerable&lt;Stream&gt; ToXmlStreamParts&lt;T&gt;(<br />
this IEnumerable&lt;T&gt; items,<br />
string rootName = null,<br />
string rootNamespace = null)<br />
{<br />
if (rootName == null)<br />
{<br />
rootName = "ArrayOfItems";<br />
}<br /><br />
if (rootNamespace == null)<br />
{<br />
rootNamespace = "";<br />
}<br /><br />
var serializer = new DataContractSerializer(typeof(T));<br />
var stream = new MemoryStream();<br />
var writer = XmlDictionaryWriter.CreateTextWriter(stream);<br /><br />
writer.WriteStartDocument();<br />
writer.WriteStartElement(rootName, rootNamespace);<br />
writer.WriteXmlnsAttribute("s", XmlSchema.Namespace);<br />
writer.WriteXmlnsAttribute("i", XmlSchema.InstanceNamespace);<br /><br />
foreach(var item in items)<br />
{<br />
serializer.WriteObject(writer, item);<br />
writer.WriteString(" ");<br /><br />
writer.Flush();<br />
stream.Position = 0;<br /><br />
yield return stream;<br /><br />
stream.Position = 0;<br />
stream.SetLength(0);<br />
}<br /><br />
writer.WriteEndElement();<br />
writer.WriteEndDocument();<br /><br />
writer.Flush();<br />
stream.Position = 0;<br /><br />
yield return stream;<br />
}<br /><br />
private class JoinedStream: Stream<br />
{<br />
public JoinedStream(IEnumerable&lt;Stream&gt; streams, bool closeStreams = true)<br />
...<br />
}<br />
} </code>
        </p>
        <p>
The use is even more simple:
</p>
        <p>
          <code> // We have a streamed business data.<br />
var people = GetPeople();<br /><br />
// We want to see it as streamed xml data.<br />
using(var stream = people.ToXmlStream("persons", "http://www.nesterovsky-bros.com"))<br />
using(var reader = XmlReader.Create(stream))<br />
{<br />
...<br />
}</code>
        </p>
        <p>
We have packed the sample into the project <a href="http://www.nesterovsky-bros.com/download/Streaming.zip">Streaming.zip</a>.
</p>
        <p>
In the <a href="http://www.nesterovsky-bros.com/weblog/2012/07/26/StreamingXsltTransformationWithForwardXPathNavigator.aspx">next
post</a> we're going to remind about streaming processing in xslt. 
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=60b3cb37-5da9-4f28-a35f-38d1ef3cccce" />
      </body>
      <title>Streaming entity data</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,60b3cb37-5da9-4f28-a35f-38d1ef3cccce.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/07/22/StreamingEntityData.aspx</link>
      <pubDate>Sun, 22 Jul 2012 20:38:29 GMT</pubDate>
      <description>  &lt;p&gt;
For some reason neither .NET&amp;#39;s &lt;code&gt;XmlSerializer&lt;/code&gt; nor &lt;code&gt;DataContractSerializer&lt;/code&gt; allow
reading data through an &lt;code&gt;XmlReader&lt;/code&gt;. These APIs work other way round writing
data into an &lt;code&gt;XmlWriter&lt;/code&gt;. To get data through &lt;code&gt;XmlReader&lt;/code&gt; one
needs to write it to some destination like a file or memory stream, and then to read
it using &lt;code&gt;XmlReader&lt;/code&gt;. This complicates streaming design considerably.
&lt;/p&gt;
&lt;p&gt;
In fact the very same happens with other .NET APIs.
&lt;/p&gt;
&lt;p&gt;
We think the reason of why .NET designers preferred &lt;code&gt;XmlWriter&lt;/code&gt; to &lt;code&gt;XmlReader&lt;/code&gt; in
those APIs is that &lt;code&gt;XmlReader&lt;/code&gt;&amp;#39;s implementation is a state machine
like, while &lt;code&gt;XmlWriter&lt;/code&gt;&amp;#39;s implementation looks like a regular procedure.
It&amp;#39;s much harder to &lt;strong&gt;manually&lt;/strong&gt; write and to support a correct state
machine logic than a procedure.
&lt;/p&gt;
&lt;p&gt;
If history would have gone slightly different way, and if yield return, lambda, and
Enumerator API appeared before &lt;code&gt;XmlReader&lt;/code&gt;, and &lt;code&gt;XmlWriter&lt;/code&gt; then,
we think, both these classes looked differently. Xml source would have been described
with a &lt;code&gt;IEnumerable&amp;lt;XmlEvent&amp;gt;&lt;/code&gt; instead of &lt;code&gt;XmlReader&lt;/code&gt;,
and &lt;code&gt;XmlWriter&lt;/code&gt; must be looked like a function receiving &lt;code&gt;IEnumerable&amp;lt;XmlEvent&amp;gt;&lt;/code&gt;.
Implementing &lt;code&gt;XmlReader&lt;/code&gt; would have meant a creating a enumerator. Yield
return and Enumerable API would have helped to implement it in a procedural way.
&lt;/p&gt;
&lt;p&gt;
But in our present we have to deal with the fact that &lt;code&gt;DataContractSerializer&lt;/code&gt; should
write the data into &lt;code&gt;XmlWriter&lt;/code&gt;, so let&amp;#39;s assume we have a project
that uses Entity Framework to access the database, and that you have a data class &lt;code&gt;Person&lt;/code&gt;,
and data access method &lt;code&gt;GetPeople()&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; [DataContract(Name = &amp;quot;person&amp;quot;, Namespace = &amp;quot;http://www.nesterovsky-bros.com&amp;quot;)]&lt;br /&gt;
public class Person 
&lt;br /&gt;
{ 
&lt;br /&gt;
[DataMember] public int Id { get; set; } 
&lt;br /&gt;
[DataMember] public string FirstName { get; set; } 
&lt;br /&gt;
[DataMember] public string LastName { get; set; } 
&lt;br /&gt;
[DataMember] public string City { get; set; } 
&lt;br /&gt;
[DataMember] public string Title { get; set; } 
&lt;br /&gt;
[DataMember] public DateTime BirthDate { get; set; } 
&lt;br /&gt;
[DataMember] public int Age { get; set; } 
&lt;br /&gt;
} 
&lt;br /&gt;
&lt;br /&gt;
public static IEnumerable&amp;lt;Person&amp;gt; GetPeople() { ... }&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
And your goal is to expose result of &lt;code&gt;GetPeople()&lt;/code&gt; as &lt;code&gt;XmlReader&lt;/code&gt;.
We achieve result with three simple steps:
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Define &lt;code&gt;JoinedStream&lt;/code&gt; - an input &lt;code&gt;Stream&lt;/code&gt; implementation that
reads data from a enumeration of streams (&lt;code&gt;IEnumerable&amp;lt;Stream&amp;gt;&lt;/code&gt;).&lt;/li&gt;
&lt;li&gt;
Build xml parts in the form of &lt;code&gt;IEnumerable&amp;lt;Stream&amp;gt;&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
Combine parts into final xml stream.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
The code is rather simple, so here we qoute its essential part:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; public static class Extensions&lt;br /&gt;
{&lt;br /&gt;
public static Stream JoinStreams(this IEnumerable&amp;lt;Stream&amp;gt; streams, bool closeStreams
= true)&lt;br /&gt;
{&lt;br /&gt;
return new JoinedStream(streams, closeStreams);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public static Stream ToXmlStream&amp;lt;T&amp;gt;(&lt;br /&gt;
this IEnumerable&amp;lt;T&amp;gt; items, 
&lt;br /&gt;
string rootName = null, 
&lt;br /&gt;
string rootNamespace = null)&lt;br /&gt;
{&lt;br /&gt;
return items.ToXmlStreamParts&amp;lt;T&amp;gt;(rootName, rootNamespace).&lt;br /&gt;
JoinStreams(false);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private static IEnumerable&amp;lt;Stream&amp;gt; ToXmlStreamParts&amp;lt;T&amp;gt;(&lt;br /&gt;
this IEnumerable&amp;lt;T&amp;gt; items,&lt;br /&gt;
string rootName = null,&lt;br /&gt;
string rootNamespace = null)&lt;br /&gt;
{&lt;br /&gt;
if (rootName == null)&lt;br /&gt;
{&lt;br /&gt;
rootName = "ArrayOfItems";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
if (rootNamespace == null)&lt;br /&gt;
{&lt;br /&gt;
rootNamespace = "";&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
var serializer = new DataContractSerializer(typeof(T));&lt;br /&gt;
var stream = new MemoryStream();&lt;br /&gt;
var writer = XmlDictionaryWriter.CreateTextWriter(stream);&lt;br /&gt;
&lt;br /&gt;
writer.WriteStartDocument();&lt;br /&gt;
writer.WriteStartElement(rootName, rootNamespace);&lt;br /&gt;
writer.WriteXmlnsAttribute("s", XmlSchema.Namespace);&lt;br /&gt;
writer.WriteXmlnsAttribute("i", XmlSchema.InstanceNamespace);&lt;br /&gt;
&lt;br /&gt;
foreach(var item in items)&lt;br /&gt;
{&lt;br /&gt;
serializer.WriteObject(writer, item);&lt;br /&gt;
writer.WriteString(" ");&lt;br /&gt;
&lt;br /&gt;
writer.Flush();&lt;br /&gt;
stream.Position = 0;&lt;br /&gt;
&lt;br /&gt;
yield return stream;&lt;br /&gt;
&lt;br /&gt;
stream.Position = 0;&lt;br /&gt;
stream.SetLength(0);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
writer.WriteEndElement();&lt;br /&gt;
writer.WriteEndDocument();&lt;br /&gt;
&lt;br /&gt;
writer.Flush();&lt;br /&gt;
stream.Position = 0;&lt;br /&gt;
&lt;br /&gt;
yield return stream;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private class JoinedStream: Stream&lt;br /&gt;
{&lt;br /&gt;
public JoinedStream(IEnumerable&amp;lt;Stream&amp;gt; streams, bool closeStreams = true)&lt;br /&gt;
...&lt;br /&gt;
}&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
The use is even more simple:
&lt;/p&gt;
&lt;p&gt;
&lt;code&gt; // We have a streamed business data.&lt;br /&gt;
var people = GetPeople();&lt;br /&gt;
&lt;br /&gt;
// We want to see it as streamed xml data.&lt;br /&gt;
using(var stream = people.ToXmlStream("persons", "http://www.nesterovsky-bros.com"))&lt;br /&gt;
using(var reader = XmlReader.Create(stream))&lt;br /&gt;
{&lt;br /&gt;
...&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
We have packed the sample into the project &lt;a href="http://www.nesterovsky-bros.com/download/Streaming.zip"&gt;Streaming.zip&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
In the &lt;a href="http://www.nesterovsky-bros.com/weblog/2012/07/26/StreamingXsltTransformationWithForwardXPathNavigator.aspx"&gt;next
post&lt;/a&gt; we&amp;#39;re going to remind about streaming processing in xslt. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=60b3cb37-5da9-4f28-a35f-38d1ef3cccce" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,60b3cb37-5da9-4f28-a35f-38d1ef3cccce.aspx</comments>
      <category>.NET</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=558eebcd-e6b3-4238-b8dc-21d0eccaf510</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,558eebcd-e6b3-4238-b8dc-21d0eccaf510.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,558eebcd-e6b3-4238-b8dc-21d0eccaf510.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=558eebcd-e6b3-4238-b8dc-21d0eccaf510</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Some time ago we were taking a part in a project where 95% of all sources are xslt
2.0. It was a great experience for us. 
</p>
        <p>
The interesting part is that we used xslt in areas we would never expect it in early
2000s. It crunched gigabytes of data in offline, while earlier we generally sought
xslt application in a browser or on a server as an engine to render the data.
</p>
        <p>
Web applications (both .NET and java) are in our focus today, and it became hard to
find application for xslt or xquery.
</p>
        <p>
Indeed, client side now have a very strong APIs: jquery, jqueryui, jsview, jqgrid,
kendoui, and so on. These libraries, and today's browsers cover developer's needs
in building managable applications. In contrast, a native support of xslt (at least
v2) does not exist in browsers.
</p>
        <p>
Server side at present is seen as a set of web services. These services support both
xml and json formats, and implement a business logic only. It would be a torture to
try to write such a frontend in xslt/xquery. A server logic itself is often dealing
with a diversity of data sources like databases, files (including xml files) and other.
</p>
        <p>
As for a database (we primarily work with SQL Server 2008 R2), we think that all communication
should go through stored procedures, which implement all data logic. Clearly, this
place is not for xslt. However, those who know sql beyond its basics can confirm that
sql is very similar to xquery. More than that SQL Server (and other databases) integrate
xquery to work with xml data, and we do use it extensively.
</p>
        <p>
Server logic itself uses API like LINQ to manipulate with different data sources.
In fact, we think that one can build a compiler from xquery 3.0 to C# with LINQ. Other
way round compiler would be a whole different story.
</p>
        <p>
The net result is that we see little place for xslt and xquery. Well, after all it's
only a personal perspective on the subject. The similar type of thing has happened
to us with C++. As with xslt/xquery we love C++ very much, and we fond of C++11, but
at present we have no place in our current projects for C++. That's pitty.
</p>
        <p>
P.S. Among other things that play against xslt/xquery is that there is a shortage
of people who know these languages, thus who can support such projects.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=558eebcd-e6b3-4238-b8dc-21d0eccaf510" />
      </body>
      <title>xslt/xquery</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,558eebcd-e6b3-4238-b8dc-21d0eccaf510.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/05/08/xsltxquery.aspx</link>
      <pubDate>Tue, 08 May 2012 20:28:51 GMT</pubDate>
      <description>  &lt;p&gt;
Some time ago we were taking a part in a project where 95% of all sources are xslt
2.0. It was a great experience for us. 
&lt;/p&gt;
&lt;p&gt;
The interesting part is that we used xslt in areas we would never expect it in early
2000s. It crunched gigabytes of data in offline, while earlier we generally sought
xslt application in a browser or on a server as an engine to render the data.
&lt;/p&gt;
&lt;p&gt;
Web applications (both .NET and java) are in our focus today, and it became hard to
find application for xslt or xquery.
&lt;/p&gt;
&lt;p&gt;
Indeed, client side now have a very strong APIs: jquery, jqueryui, jsview, jqgrid,
kendoui, and so on. These libraries, and today's browsers cover developer's needs
in building managable applications. In contrast, a native support of xslt (at least
v2) does not exist in browsers.
&lt;/p&gt;
&lt;p&gt;
Server side at present is seen as a set of web services. These services support both
xml and json formats, and implement a business logic only. It would be a torture to
try to write such a frontend in xslt/xquery. A server logic itself is often dealing
with a diversity of data sources like databases, files (including xml files) and other.
&lt;/p&gt;
&lt;p&gt;
As for a database (we primarily work with SQL Server 2008 R2), we think that all communication
should go through stored procedures, which implement all data logic. Clearly, this
place is not for xslt. However, those who know sql beyond its basics can confirm that
sql is very similar to xquery. More than that SQL Server (and other databases) integrate
xquery to work with xml data, and we do use it extensively.
&lt;/p&gt;
&lt;p&gt;
Server logic itself uses API like LINQ to manipulate with different data sources.
In fact, we think that one can build a compiler from xquery 3.0 to C# with LINQ. Other
way round compiler would be a whole different story.
&lt;/p&gt;
&lt;p&gt;
The net result is that we see little place for xslt and xquery. Well, after all it's
only a personal perspective on the subject. The similar type of thing has happened
to us with C++. As with xslt/xquery we love C++ very much, and we fond of C++11, but
at present we have no place in our current projects for C++. That's pitty.
&lt;/p&gt;
&lt;p&gt;
P.S. Among other things that play against xslt/xquery is that there is a shortage
of people who know these languages, thus who can support such projects.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=558eebcd-e6b3-4238-b8dc-21d0eccaf510" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,558eebcd-e6b3-4238-b8dc-21d0eccaf510.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=19c9c7e3-4b24-4407-806a-b118460873e3</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,19c9c7e3-4b24-4407-806a-b118460873e3.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,19c9c7e3-4b24-4407-806a-b118460873e3.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=19c9c7e3-4b24-4407-806a-b118460873e3</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This time we <a href="http://www.nesterovsky-bros.com/download/languages-xom.zip">update
csharpxom</a> to adjust it to C# 4.5. Additions are<a href="http://msdn.microsoft.com/en-us/library/hh156513(v=vs.110).aspx"><code>async</code> modifier</a> and <a href="http://msdn.microsoft.com/en-us/library/hh156528(v=vs.110).aspx"><code>await</code> operator</a>.
</p>
        <p>
They are used to simplify asynchronous programming.
</p>
        <p>
The following example from the msdn:
</p>
        <p style="padding-left: 1em">
          <code>private async Task&lt;byte[]&gt; GetURLContentsAsync(string url)<br />
{<br />
var content = new MemoryStream();<br />
var request = (HttpWebRequest)WebRequest.Create(url);<br /><br />
using(var response = await request.GetResponseAsync())<br />
using(var responseStream = response.GetResponseStream())<br />
{<br />
await responseStream.CopyToAsync(content);<br />
}<br /><br />
return content.ToArray();<br />
}</code>
        </p>
        <p>
looks like this in csharpxom:
</p>
        <p style="padding-left: 1em">
          <code>&lt;method name="GetURLContentsAsync" access="private" <span style="font-weight: bold">async="true"</span>&gt;<br />
&lt;returns&gt;<br />
&lt;type name="Task" namespace="System.Threading.Tasks"&gt;<br />
&lt;type-arguments&gt;<br />
&lt;type name="byte" rank="1"/&gt;<br />
&lt;/type-arguments&gt;<br />
&lt;/type&gt;<br />
&lt;/returns&gt;<br />
&lt;parameters&gt;<br />
&lt;parameter name="url"&gt;<br />
&lt;type name="string"/&gt;<br />
&lt;/parameter&gt;<br />
&lt;/parameters&gt;<br />
&lt;block&gt;<br />
&lt;var name="content"&gt;<br />
&lt;initialize&gt;<br />
&lt;new-object&gt;<br />
&lt;type name="MemoryStream" namespace="System.IO"/&gt;<br />
&lt;/new-object&gt;<br />
&lt;/initialize&gt;<br />
&lt;/var&gt;<br />
&lt;var name="request"&gt;<br />
&lt;initialize&gt;<br />
&lt;cast&gt;<br />
&lt;invoke&gt;<br />
&lt;static-method-ref name="Create"&gt;<br />
&lt;type name="WebRequest" namespace="System.Net"/&gt;<br />
&lt;/static-method-ref&gt;<br />
&lt;arguments&gt;<br />
&lt;var-ref name="url"/&gt;<br />
&lt;/arguments&gt;<br />
&lt;/invoke&gt;<br />
&lt;type name="HttpWebRequest" namespace="System.Net"/&gt;<br />
&lt;/cast&gt;<br />
&lt;/initialize&gt;<br />
&lt;/var&gt;<br /><br />
&lt;using&gt;<br />
&lt;resource&gt;<br />
&lt;var name="response"&gt;<br />
&lt;initialize&gt;<br /><span style="font-weight: bold">&lt;await&gt;</span><br />
&lt;invoke&gt;<br />
&lt;method-ref name="GetResponseAsync"&gt;<br />
&lt;var-ref name="request"/&gt;<br />
&lt;/method-ref&gt;<br />
&lt;/invoke&gt;<br /><span style="font-weight: bold">&lt;/await&gt;</span><br />
&lt;/initialize&gt;<br />
&lt;/var&gt;<br />
&lt;/resource&gt;<br />
&lt;using&gt;<br />
&lt;resource&gt;<br />
&lt;var name="responseStream"&gt;<br />
&lt;initialize&gt;<br />
&lt;invoke&gt;<br />
&lt;method-ref name="GetResponseStream"&gt;<br />
&lt;var-ref name="response"/&gt;<br />
&lt;/method-ref&gt;<br />
&lt;/invoke&gt;<br />
&lt;/initialize&gt;<br />
&lt;/var&gt;<br />
&lt;/resource&gt;<br />
&lt;expression&gt;<br /><span style="font-weight: bold">&lt;await&gt;</span><br />
&lt;invoke&gt;<br />
&lt;method-ref name="CopyToAsync"&gt;<br />
&lt;var-ref name="responseStream"/&gt;<br />
&lt;/method-ref&gt;<br />
&lt;arguments&gt;<br />
&lt;var-ref name="content"/&gt;<br />
&lt;/arguments&gt;<br />
&lt;/invoke&gt;<br /><span style="font-weight: bold">&lt;/await&gt;</span><br />
&lt;/expression&gt;<br />
&lt;/using&gt;<br />
&lt;/using&gt;<br /><br />
&lt;return&gt;<br />
&lt;invoke&gt;<br />
&lt;method-ref name="ToArray"&gt;<br />
&lt;var-ref name="content"/&gt;<br />
&lt;/method-ref&gt;<br />
&lt;/invoke&gt;<br />
&lt;/return&gt;<br />
&lt;/block&gt;<br />
&lt;/method&gt;</code>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=19c9c7e3-4b24-4407-806a-b118460873e3" />
      </body>
      <title>Languages XOM update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,19c9c7e3-4b24-4407-806a-b118460873e3.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2012/03/23/LanguagesXOMUpdate.aspx</link>
      <pubDate>Fri, 23 Mar 2012 00:07:35 GMT</pubDate>
      <description>  &lt;p&gt;
This time we &lt;a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"&gt;update
csharpxom&lt;/a&gt; to adjust it to C# 4.5. Additions are&lt;a href="http://msdn.microsoft.com/en-us/library/hh156513(v=vs.110).aspx"&gt; &lt;code&gt;async&lt;/code&gt; modifier&lt;/a&gt; and &lt;a href="http://msdn.microsoft.com/en-us/library/hh156528(v=vs.110).aspx"&gt; &lt;code&gt;await&lt;/code&gt; operator&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
They are used to simplify asynchronous programming.
&lt;/p&gt;
&lt;p&gt;
The following example from the msdn:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;private async Task&amp;lt;byte[]&amp;gt; GetURLContentsAsync(string url)&lt;br /&gt;
{&lt;br /&gt;
var content = new MemoryStream();&lt;br /&gt;
var request = (HttpWebRequest)WebRequest.Create(url);&lt;br /&gt;
&lt;br /&gt;
using(var response = await request.GetResponseAsync())&lt;br /&gt;
using(var responseStream = response.GetResponseStream())&lt;br /&gt;
{&lt;br /&gt;
await responseStream.CopyToAsync(content);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return content.ToArray();&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
looks like this in csharpxom:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;method name="GetURLContentsAsync" access="private" &lt;span style="font-weight: bold"&gt;async="true"&lt;/span&gt;&amp;gt;&lt;br /&gt;
&amp;lt;returns&amp;gt;&lt;br /&gt;
&amp;lt;type name="Task" namespace="System.Threading.Tasks"&amp;gt;&lt;br /&gt;
&amp;lt;type-arguments&amp;gt;&lt;br /&gt;
&amp;lt;type name="byte" rank="1"/&amp;gt;&lt;br /&gt;
&amp;lt;/type-arguments&amp;gt;&lt;br /&gt;
&amp;lt;/type&amp;gt;&lt;br /&gt;
&amp;lt;/returns&amp;gt;&lt;br /&gt;
&amp;lt;parameters&amp;gt;&lt;br /&gt;
&amp;lt;parameter name="url"&amp;gt;&lt;br /&gt;
&amp;lt;type name="string"/&amp;gt;&lt;br /&gt;
&amp;lt;/parameter&amp;gt;&lt;br /&gt;
&amp;lt;/parameters&amp;gt;&lt;br /&gt;
&amp;lt;block&amp;gt;&lt;br /&gt;
&amp;lt;var name="content"&amp;gt;&lt;br /&gt;
&amp;lt;initialize&amp;gt;&lt;br /&gt;
&amp;lt;new-object&amp;gt;&lt;br /&gt;
&amp;lt;type name="MemoryStream" namespace="System.IO"/&amp;gt;&lt;br /&gt;
&amp;lt;/new-object&amp;gt;&lt;br /&gt;
&amp;lt;/initialize&amp;gt;&lt;br /&gt;
&amp;lt;/var&amp;gt;&lt;br /&gt;
&amp;lt;var name="request"&amp;gt;&lt;br /&gt;
&amp;lt;initialize&amp;gt;&lt;br /&gt;
&amp;lt;cast&amp;gt;&lt;br /&gt;
&amp;lt;invoke&amp;gt;&lt;br /&gt;
&amp;lt;static-method-ref name="Create"&amp;gt;&lt;br /&gt;
&amp;lt;type name="WebRequest" namespace="System.Net"/&amp;gt;&lt;br /&gt;
&amp;lt;/static-method-ref&amp;gt;&lt;br /&gt;
&amp;lt;arguments&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="url"/&amp;gt;&lt;br /&gt;
&amp;lt;/arguments&amp;gt;&lt;br /&gt;
&amp;lt;/invoke&amp;gt;&lt;br /&gt;
&amp;lt;type name="HttpWebRequest" namespace="System.Net"/&amp;gt;&lt;br /&gt;
&amp;lt;/cast&amp;gt;&lt;br /&gt;
&amp;lt;/initialize&amp;gt;&lt;br /&gt;
&amp;lt;/var&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;using&amp;gt;&lt;br /&gt;
&amp;lt;resource&amp;gt;&lt;br /&gt;
&amp;lt;var name="response"&amp;gt;&lt;br /&gt;
&amp;lt;initialize&amp;gt;&lt;br /&gt;
&lt;span style="font-weight: bold"&gt;&amp;lt;await&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&amp;lt;invoke&amp;gt;&lt;br /&gt;
&amp;lt;method-ref name="GetResponseAsync"&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="request"/&amp;gt;&lt;br /&gt;
&amp;lt;/method-ref&amp;gt;&lt;br /&gt;
&amp;lt;/invoke&amp;gt;&lt;br /&gt;
&lt;span style="font-weight: bold"&gt;&amp;lt;/await&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&amp;lt;/initialize&amp;gt;&lt;br /&gt;
&amp;lt;/var&amp;gt;&lt;br /&gt;
&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;using&amp;gt;&lt;br /&gt;
&amp;lt;resource&amp;gt;&lt;br /&gt;
&amp;lt;var name="responseStream"&amp;gt;&lt;br /&gt;
&amp;lt;initialize&amp;gt;&lt;br /&gt;
&amp;lt;invoke&amp;gt;&lt;br /&gt;
&amp;lt;method-ref name="GetResponseStream"&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="response"/&amp;gt;&lt;br /&gt;
&amp;lt;/method-ref&amp;gt;&lt;br /&gt;
&amp;lt;/invoke&amp;gt;&lt;br /&gt;
&amp;lt;/initialize&amp;gt;&lt;br /&gt;
&amp;lt;/var&amp;gt;&lt;br /&gt;
&amp;lt;/resource&amp;gt;&lt;br /&gt;
&amp;lt;expression&amp;gt;&lt;br /&gt;
&lt;span style="font-weight: bold"&gt;&amp;lt;await&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&amp;lt;invoke&amp;gt;&lt;br /&gt;
&amp;lt;method-ref name="CopyToAsync"&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="responseStream"/&amp;gt;&lt;br /&gt;
&amp;lt;/method-ref&amp;gt;&lt;br /&gt;
&amp;lt;arguments&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="content"/&amp;gt;&lt;br /&gt;
&amp;lt;/arguments&amp;gt;&lt;br /&gt;
&amp;lt;/invoke&amp;gt;&lt;br /&gt;
&lt;span style="font-weight: bold"&gt;&amp;lt;/await&amp;gt;&lt;/span&gt;
&lt;br /&gt;
&amp;lt;/expression&amp;gt;&lt;br /&gt;
&amp;lt;/using&amp;gt;&lt;br /&gt;
&amp;lt;/using&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;return&amp;gt;&lt;br /&gt;
&amp;lt;invoke&amp;gt;&lt;br /&gt;
&amp;lt;method-ref name="ToArray"&amp;gt;&lt;br /&gt;
&amp;lt;var-ref name="content"/&amp;gt;&lt;br /&gt;
&amp;lt;/method-ref&amp;gt;&lt;br /&gt;
&amp;lt;/invoke&amp;gt;&lt;br /&gt;
&amp;lt;/return&amp;gt;&lt;br /&gt;
&amp;lt;/block&amp;gt;&lt;br /&gt;
&amp;lt;/method&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=19c9c7e3-4b24-4407-806a-b118460873e3" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,19c9c7e3-4b24-4407-806a-b118460873e3.aspx</comments>
      <category>.NET</category>
      <category>Announce</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=08d97135-32ca-4586-bdf4-410ef43f8ebe</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,08d97135-32ca-4586-bdf4-410ef43f8ebe.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,08d97135-32ca-4586-bdf4-410ef43f8ebe.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=08d97135-32ca-4586-bdf4-410ef43f8ebe</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p style="padding-left: 1em; font-style: italic">
          <a href="http://twitter.com/#!/michaelhkay/statuses/145259939055673344">@michaelhkay
Saxon 9.4 is out.</a>
        </p>
        <p>
But why author does not state that HE version is still xslt/xpath 2.0, as neither
xslt maps, nor function items are supported.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=08d97135-32ca-4586-bdf4-410ef43f8ebe" />
      </body>
      <title>Saxon 9.4 is out</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,08d97135-32ca-4586-bdf4-410ef43f8ebe.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/12/10/Saxon94IsOut.aspx</link>
      <pubDate>Sat, 10 Dec 2011 12:16:28 GMT</pubDate>
      <description>&lt;p style="padding-left: 1em; font-style: italic"&gt;
&lt;a href="http://twitter.com/#!/michaelhkay/statuses/145259939055673344"&gt;@michaelhkay
Saxon 9.4 is out.&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
But why author does not state that HE version is still xslt/xpath 2.0, as neither
xslt maps, nor function items are supported.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=08d97135-32ca-4586-bdf4-410ef43f8ebe" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,08d97135-32ca-4586-bdf4-410ef43f8ebe.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ad1c5ce2-4806-4de7-8c58-6af54cb9df06</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ad1c5ce2-4806-4de7-8c58-6af54cb9df06</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
It has happened so, that we have never worked with jQuery, however were aware of it.
</p>
        <p>
In early 2000 we have developed a web application that contained rich javascript APIs,
including UI components. Later, we were actively practicing in ASP.NET, and later
in JSF.
</p>
        <p>
At present, looking at jQuery more closely we regret that we have failed to start
using it earlier.
</p>
        <p>
Separation of business logic and presentation is remarkable when one uses JSON web
services. In fact server part can be seen as a set of web services representing a
business logic and a set of resources: html, styles, scripts, others. Nor ASP.NET
or JSF approach such a consistent separation.
</p>
        <p>
The only trouble, in our opinion, is that jQuery has no standard data binding: a way
to bind JSON data to (and from) html controls. The technique that will probably be
standardized is called <a href="https://github.com/BorisMoore/jsviews">jQuery Templates
or JsViews </a> .
</p>
        <p>
Unfortunatelly after reading about this <a href="http://wiki.jqueryui.com/w/page/37898666/Template">binding
API</a>, and being in love with Xslt and XQuery we just want to cry. We don't know
what would be the best solution for the task, but what we see looks uncomfortable
to us.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06" />
      </body>
      <title>jQuery</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/10/28/jQuery.aspx</link>
      <pubDate>Fri, 28 Oct 2011 22:59:23 GMT</pubDate>
      <description>&lt;p&gt;
It has happened so, that we have never worked with jQuery, however were aware of it.
&lt;/p&gt;
&lt;p&gt;
In early 2000 we have developed a web application that contained rich javascript APIs,
including UI components. Later, we were actively practicing in ASP.NET, and later
in JSF.
&lt;/p&gt;
&lt;p&gt;
At present, looking at jQuery more closely we regret that we have failed to start
using it earlier.
&lt;/p&gt;
&lt;p&gt;
Separation of business logic and presentation is remarkable when one uses JSON web
services. In fact server part can be seen as a set of web services representing a
business logic and a set of resources: html, styles, scripts, others. Nor ASP.NET
or JSF approach such a consistent separation.
&lt;/p&gt;
&lt;p&gt;
The only trouble, in our opinion, is that jQuery has no standard data binding: a way
to bind JSON data to (and from) html controls. The technique that will probably be
standardized is called &lt;a href="https://github.com/BorisMoore/jsviews"&gt;jQuery Templates
or JsViews &lt;/a&gt; .
&lt;/p&gt;
&lt;p&gt;
Unfortunatelly after reading about this &lt;a href="http://wiki.jqueryui.com/w/page/37898666/Template"&gt;binding
API&lt;/a&gt;, and being in love with Xslt and XQuery we just want to cry. We don't know
what would be the best solution for the task, but what we see looks uncomfortable
to us.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ad1c5ce2-4806-4de7-8c58-6af54cb9df06" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ad1c5ce2-4806-4de7-8c58-6af54cb9df06.aspx</comments>
      <category>ASP.NET</category>
      <category>JSF and Facelets</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=9c7823a7-6ac4-41ca-a75a-de10204879cd</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9c7823a7-6ac4-41ca-a75a-de10204879cd.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9c7823a7-6ac4-41ca-a75a-de10204879cd.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=9c7823a7-6ac4-41ca-a75a-de10204879cd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
A couple of weeks ago, we have suggested to introduce a enumerator function into the
XPath (see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=14152"> [F+O30]
A enumerator function</a>):
</p>
        <p style="font-style: italic; padding-left: 1em">
I would like the WG to consider an addition of a function that turns a sequence into
a enumeration of values.<br /><br />
Consider a function like this:  fn:enumerator($items as item()*) as function()
as item()<span style="font-weight: bold">?</span>;<br /><br />
alternatively, signature could be:<br /><br />
 fn:enumerator($items as function() as item()*) as function() as item()<span style="font-weight: bold">?</span>;<br /><br />
This function receives a sequence, and returns a function item, which upon N's
call shall return N's element of the original sequence. This way, a sequence of
items is turned into a function providing a enumeration of items of the sequence. 
<br /><br />
As an example consider two functions:<br /><br />
a) t:rand($seed as xs:double) as xs:double* - a function producing a random number
sequence;<br />
b) t:work($input as element()) as element() - a function that generates output from
it's input, and that needs random numbers in the course of the execution. 
<br /><br />
t:work() may contain a code like this:<br />
  let $rand := fn:enumerator(t:rand($seed)),<br /><br />
and later it can call $rand() to get a random numbers. 
<br /><br />
Enumerators will help to compose algorithms where one algorithm communicate with other
independant algorithms, thus making code simpler. The most obvious class of enumerators
are generators: ordered numbers, unique identifiers, random numbers. 
<br /><br />
Technically, <span style="font-weight: bold">function returned from</span> fn:enumerator()
is nondetermenistic, but its "side effect" is similar to a "side effect"
of a function generate-id() from a newly created node (see <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13747" title="RESOLVED LATER - [XPath 3.0] Determinism of expressions returning constructed nodes">bug
#13747</a>, and <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13494" title="NEW - Node uniqueness returned from XSLT function.">bug
#13494</a>). 
</p>
        <p>
The idea is inspired by a generator function, which returns a new value upon each
call. 
</p>
        <p>
Such function can be seen as a stateful object. But our goal is to look at it in a
more functional way. So, we look at the algorithm as a function that produces a sequence
of output, which is pure functional; and an enumerator that allows to iterate over
algorithm's output.
</p>
        <p>
This way, we see the function that implements an algorithm and the function that uses
it can be seen as two thread of functional programs that use messaging to communicate
to each other.
</p>
        <p>
Honestly, we doubt that WG will accept it, but it's interesting to watch the discussion.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd" />
      </body>
      <title>An XPath enumerator function</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,9c7823a7-6ac4-41ca-a75a-de10204879cd.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/09/29/AnXPathEnumeratorFunction.aspx</link>
      <pubDate>Thu, 29 Sep 2011 11:56:05 GMT</pubDate>
      <description>&lt;p&gt;
A couple of weeks ago, we have suggested to introduce a enumerator function into the
XPath (see &lt;a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=14152"&gt; [F+O30]
A enumerator function&lt;/a&gt;):
&lt;/p&gt;
&lt;p style="font-style: italic; padding-left: 1em"&gt;
I would like the WG to consider an addition of a function that turns a sequence into
a enumeration of values.&lt;br /&gt;
&lt;br /&gt;
Consider a function like this: &amp;nbsp;fn:enumerator($items as item()*) as function()
as item()&lt;span style="font-weight: bold"&gt;?&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
alternatively, signature could be:&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;fn:enumerator($items as function() as item()*) as function() as item()&lt;span style="font-weight: bold"&gt;?&lt;/span&gt;;&lt;br /&gt;
&lt;br /&gt;
This function receives a sequence, and returns a function item, which upon N&amp;#39;s
call shall return N&amp;#39;s element of the original sequence. This way, a sequence of
items is turned into a function providing a enumeration of items of the sequence. 
&lt;br /&gt;
&lt;br /&gt;
As an example consider two functions:&lt;br /&gt;
&lt;br /&gt;
a) t:rand($seed as xs:double) as xs:double* - a function producing a random number
sequence;&lt;br /&gt;
b) t:work($input as element()) as element() - a function that generates output from
it&amp;#39;s input, and that needs random numbers in the course of the execution. 
&lt;br /&gt;
&lt;br /&gt;
t:work() may contain a code like this:&lt;br /&gt;
&amp;nbsp; let $rand := fn:enumerator(t:rand($seed)),&lt;br /&gt;
&lt;br /&gt;
and later it can call $rand() to get a random numbers. 
&lt;br /&gt;
&lt;br /&gt;
Enumerators will help to compose algorithms where one algorithm communicate with other
independant algorithms, thus making code simpler. The most obvious class of enumerators
are generators: ordered numbers, unique identifiers, random numbers. 
&lt;br /&gt;
&lt;br /&gt;
Technically, &lt;span style="font-weight: bold"&gt;function returned from&lt;/span&gt; fn:enumerator()
is nondetermenistic, but its &amp;quot;side effect&amp;quot; is similar to a &amp;quot;side effect&amp;quot;
of a function generate-id() from a newly created node (see &lt;a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13747" title="RESOLVED LATER - [XPath 3.0] Determinism of expressions returning constructed nodes"&gt;bug
#13747&lt;/a&gt;, and &lt;a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13494" title="NEW - Node uniqueness returned from XSLT function."&gt;bug
#13494&lt;/a&gt;). 
&lt;/p&gt;
&lt;p&gt;
The idea is inspired by a generator function, which returns a new value upon each
call. 
&lt;/p&gt;
&lt;p&gt;
Such function can be seen as a stateful object. But our goal is to look at it in a
more functional way. So, we look at the algorithm as a function that produces a sequence
of output, which is pure functional; and an enumerator that allows to iterate over
algorithm&amp;#39;s output.
&lt;/p&gt;
&lt;p&gt;
This way, we see the function that implements an algorithm and the function that uses
it can be seen as two thread of functional programs that use messaging to communicate
to each other.
&lt;/p&gt;
&lt;p&gt;
Honestly, we doubt that WG will accept it, but it&amp;#39;s interesting to watch the discussion.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=9c7823a7-6ac4-41ca-a75a-de10204879cd" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,9c7823a7-6ac4-41ca-a75a-de10204879cd.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=d0be8e77-04d9-47a0-840e-d62b1936b3ac</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d0be8e77-04d9-47a0-840e-d62b1936b3ac.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d0be8e77-04d9-47a0-840e-d62b1936b3ac.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d0be8e77-04d9-47a0-840e-d62b1936b3ac</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
More than month has passed since we have reported a problem to the saxon forum (see <a href="http://www.nesterovsky-bros.com/weblog/2011/07/27/SaxonOptimizerBug.aspx"> Saxon
optimizer bug</a> and <a href="http://sourceforge.net/projects/saxon/forums/forum/94027/topic/4621860"> Saxon
9.2 generate-id() bug)</a>. 
</p>
        <p>
The essence of the problem is that we have constructed argumentless function to return
a unique identifiers each time function is called. To achieve the effect we have created
a temporary node and returned its <code>generate-id()</code> value.
</p>
        <p>
Such a function is nondetermenistic, as we cannot state that its result depends on
arguments only. This means that engine's optimizer is not free to reorder calls to
such a function. That's what happens in Saxon 9.2, and Saxon 9.3 where engine
elevates function call out of cycle thus producing invalid results.
</p>
        <p>
Michael Kay, the author of the Saxon engine, argued that this is "a gray area
of the xslt spec":
</p>
        <p style="padding-left: 1em; font-style: italic">
If the spec were stricter about defining exactly when you can rely on identity-dependent
operations then I would be obliged to follow it, but I think it's probably deliberate
that it currently allows implementations some latitude, effectively signalling to
users that they should avoid depending on this aspect of the behaviour. 
</p>
        <p>
He adviced to raise a bug in the w3c bugzilla to resolve the issue. In the end two
related bugs have been raised:
</p>
        <ul>
          <li>
            <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13494">Bug 13494</a> - Node
uniqueness returned from XSLT function;</li>
          <li>
            <a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13747">Bug 13747</a> - [XPath
3.0] Determinism of expressions returning constructed nodes.</li>
        </ul>
        <p>
Yesterday, the WG has resolved the issue:
</p>
        <p style="padding: 1em; font-style: italic">
The Working Group agreed that default behavior should continue to require these nodes
to be constructed with unique IDs. We believe that this is the kind of thing implementations
can do with annotations or declaration options, and it would be best to get implementation
experience with this before standardizing.
</p>
        <p>
This means that the technique we used to generate unique identifiers is correct and
the behaviour is well defined.
</p>
        <p>
The only problem is to wait when Saxon will fix its behaviour accordingly.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac" />
      </body>
      <title>Resolution of the Saxon optimizer bug</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d0be8e77-04d9-47a0-840e-d62b1936b3ac.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/09/14/ResolutionOfTheSaxonOptimizerBug.aspx</link>
      <pubDate>Wed, 14 Sep 2011 05:54:56 GMT</pubDate>
      <description>&lt;p&gt;
More than month has passed since we have reported a problem to the saxon forum (see &lt;a href="http://www.nesterovsky-bros.com/weblog/2011/07/27/SaxonOptimizerBug.aspx"&gt; Saxon
optimizer bug&lt;/a&gt; and &lt;a href="http://sourceforge.net/projects/saxon/forums/forum/94027/topic/4621860"&gt; Saxon
9.2 generate-id() bug)&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
The essence of the problem is that we have constructed argumentless function to return
a unique identifiers each time function is called. To achieve the effect we have created
a temporary node and returned its &lt;code&gt;generate-id()&lt;/code&gt; value.
&lt;/p&gt;
&lt;p&gt;
Such a function is nondetermenistic, as we cannot state that its result depends on
arguments only. This means that engine's optimizer is not free to reorder calls to
such a function. That&amp;#39;s what happens in Saxon 9.2, and Saxon 9.3 where engine
elevates function call out of cycle thus producing invalid results.
&lt;/p&gt;
&lt;p&gt;
Michael Kay, the author of the Saxon engine, argued that this is &amp;quot;a gray area
of the xslt spec&amp;quot;:
&lt;/p&gt;
&lt;p style="padding-left: 1em; font-style: italic"&gt;
If the spec were stricter about defining exactly when you can rely on identity-dependent
operations then I would be obliged to follow it, but I think it&amp;#39;s probably deliberate
that it currently allows implementations some latitude, effectively signalling to
users that they should avoid depending on this aspect of the behaviour. 
&lt;/p&gt;
&lt;p&gt;
He adviced to raise a bug in the w3c bugzilla to resolve the issue. In the end two
related bugs have been raised:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13494"&gt;Bug 13494&lt;/a&gt; - Node
uniqueness returned from XSLT function;&lt;/li&gt;
&lt;li&gt;
&lt;a href="http://www.w3.org/Bugs/Public/show_bug.cgi?id=13747"&gt;Bug 13747&lt;/a&gt; - [XPath
3.0] Determinism of expressions returning constructed nodes.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Yesterday, the WG has resolved the issue:
&lt;/p&gt;
&lt;p style="padding: 1em; font-style: italic"&gt;
The Working Group agreed that default behavior should continue to require these nodes
to be constructed with unique IDs. We believe that this is the kind of thing implementations
can do with annotations or declaration options, and it would be best to get implementation
experience with this before standardizing.
&lt;/p&gt;
&lt;p&gt;
This means that the technique we used to generate unique identifiers is correct and
the behaviour is well defined.
&lt;/p&gt;
&lt;p&gt;
The only problem is to wait when Saxon will fix its behaviour accordingly.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d0be8e77-04d9-47a0-840e-d62b1936b3ac" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d0be8e77-04d9-47a0-840e-d62b1936b3ac.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=a2345b18-13e4-4f60-b798-4b28587a18cb</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a2345b18-13e4-4f60-b798-4b28587a18cb.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,a2345b18-13e4-4f60-b798-4b28587a18cb.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=a2345b18-13e4-4f60-b798-4b28587a18cb</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Recently one of users of <a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx">java
yield return annotation</a> has kindly informed us about some problem that happened
in his environment (see <a href="http://www.nesterovsky-bros.com/weblog/2011/02/05/JavasYieldReturnAnnotationUpdate.aspx"> Java's
@Yield return annotation update</a>).
</p>
        <p>
Incidentally we have never noticed the problem earlier. Along with this issue we have
found that eclipse compiler has changed in the Indigo in a way that we had to recompile
the source. Well, that's a price you have to pay when you access internal API.
</p>
        <p>
Updated sources can be found at <a href="http://www.nesterovsky-bros.com/download/java/Yield.zip">Yield.zip</a>,
and compiled jars at <a href="http://www.nesterovsky-bros.com/download/java/Yield.jar">Yield.jar</a> (pre-Indigo),
and <a href="http://www.nesterovsky-bros.com/download/java/Yield.3.7.jar"> Yield.3.7.jar</a> (Indigo
and probably higher).
</p>
        <p>
See also: 
</p>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx"> Yield
return feature in java</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/2011/01/27/WhyYieldIteratorShouldBeCloseable.aspx"> Why
@Yield iterator should be Closeable</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx"> What
you can do with jxom.</a>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb" />
      </body>
      <title>Yield return update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,a2345b18-13e4-4f60-b798-4b28587a18cb.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/08/28/YieldReturnUpdate.aspx</link>
      <pubDate>Sun, 28 Aug 2011 19:11:45 GMT</pubDate>
      <description>&lt;p&gt;
Recently one of users of &lt;a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx"&gt;java
yield return annotation&lt;/a&gt; has kindly informed us about some problem that happened
in his environment (see &lt;a href="http://www.nesterovsky-bros.com/weblog/2011/02/05/JavasYieldReturnAnnotationUpdate.aspx"&gt; Java&amp;#39;s
@Yield return annotation update&lt;/a&gt;).
&lt;/p&gt;
&lt;p&gt;
Incidentally we have never noticed the problem earlier. Along with this issue we have
found that eclipse compiler has changed in the Indigo in a way that we had to recompile
the source. Well, that&amp;#39;s a price you have to pay when you access internal API.
&lt;/p&gt;
&lt;p&gt;
Updated sources can be found at &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.zip"&gt;Yield.zip&lt;/a&gt;,
and compiled jars at &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.jar"&gt;Yield.jar&lt;/a&gt; (pre-Indigo),
and &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.3.7.jar"&gt; Yield.3.7.jar&lt;/a&gt; (Indigo
and probably higher).
&lt;/p&gt;
&lt;p&gt;
See also: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx"&gt; Yield
return feature in java&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2011/01/27/WhyYieldIteratorShouldBeCloseable.aspx"&gt; Why
@Yield iterator should be Closeable&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx"&gt; What
you can do with jxom.&lt;/a&gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=a2345b18-13e4-4f60-b798-4b28587a18cb" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,a2345b18-13e4-4f60-b798-4b28587a18cb.aspx</comments>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=d653df7e-7503-4213-8546-290c3863f0e2</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d653df7e-7503-4213-8546-290c3863f0e2.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d653df7e-7503-4213-8546-290c3863f0e2.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=d653df7e-7503-4213-8546-290c3863f0e2</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
An xslt code that worked in the production for several years failed unexpectedly.
That's unusual, unfortunate but it happens.
</p>
        <p>
We started to analyze the problem, limited the code block and recreated it in the
simpe form. That's it:
</p>
        <p style="padding: 1em">
          <code>&lt;xsl:stylesheet version="2.0"<br />
xmlns:xsl="<a href="http://www.w3.org/1999/XSL/Transform">http://www.w3.org/1999/XSL/Transform</a>"<br />
xmlns:xs="<a href="http://www.w3.org/2001/XMLSchema">http://www.w3.org/2001/XMLSchema</a>"<br />
xmlns:t="<a href="http://www.nesterovsky-bros.com/xslt/public">http://www.nesterovsky-bros.com/xslt/public</a>"<br />
exclude-result-prefixes="t xs"&gt;<br /><br />
&lt;xsl:template match="/" name="main"&gt;<br />
&lt;xsl:variable name="content"&gt;<br />
&lt;root&gt;<br />
&lt;xsl:for-each select="1 to 3"&gt;<br />
&lt;item/&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/root&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:variable name="result"&gt;<br />
&lt;root&gt;<br />
&lt;xsl:for-each select="$content/root/item"&gt;<br />
&lt;section-ref name-ref="<span style="font-weight: bold">{t:generate-id()}.s</span>"/&gt;<br />
&lt;!--<br />
&lt;xsl:variable name="id" as="xs:string"<br />
select="t:generate-id()"/&gt;<br />
&lt;section-ref name-ref="{$id}.s"/&gt;<br />
--&gt;<br />
&lt;/xsl:for-each&gt;<br />
&lt;/root&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:message select="$result"/&gt;<br />
&lt;/xsl:template&gt;<br /><br />
&lt;xsl:function name="t:generate-id" as="xs:string"&gt;<br />
&lt;xsl:variable name="element" as="element()"&gt;<br />
&lt;element/&gt;<br />
&lt;/xsl:variable&gt;<br /><br />
&lt;xsl:sequence select="generate-id($element)"/&gt;<br />
&lt;/xsl:function&gt;<br /><br />
&lt;/xsl:stylesheet&gt; </code>
        </p>
        <p>
This code performs some transformation and assigns unique values to <code>name-ref</code> attributes.
Values generated with <code>t:generate-id()</code> function are guaranteed to be unique,
as spec claims that every node has its unique <code>generate-id()</code> value.
</p>
        <p>
Imagine, what was our surprise to find that generated elements all have the same <code>name-ref</code>'s.
We studied code all over, and found no holes in our reasoning and implementation,
so our conlusion was: it's Saxon's bug!
</p>
        <p>
It's interesting enough that if we rewrite code a little (see commented part),
it starts to work properly, thus we suspect Saxon's optimizer.
</p>
        <p>
Well, in the course of development we have found and reported many Saxon bugs, but
how come that this little beetle was hiding so long.
</p>
        <p>
We've verified that the bug exists in the versions 9.2 and 9.3. Here is the bug
report: <a href="http://sourceforge.net/projects/saxon/forums/forum/94027/topic/4621860"> Saxon
9.2 generate-id() bug</a>. 
</p>
        <p>
Unfortunatelly, it's there already for three days (2011-07-25 to 2011-07-27) without
any reaction. We hope this will change soon.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2" />
      </body>
      <title>Saxon optimizer bug</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,d653df7e-7503-4213-8546-290c3863f0e2.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/07/27/SaxonOptimizerBug.aspx</link>
      <pubDate>Wed, 27 Jul 2011 20:02:38 GMT</pubDate>
      <description>&lt;p&gt;
An xslt code that worked in the production for several years failed unexpectedly.
That&amp;#39;s unusual, unfortunate but it happens.
&lt;/p&gt;
&lt;p&gt;
We started to analyze the problem, limited the code block and recreated it in the
simpe form. That&amp;#39;s it:
&lt;/p&gt;
&lt;p style="padding: 1em"&gt;
&lt;code&gt;&amp;lt;xsl:stylesheet version="2.0"&lt;br /&gt;
xmlns:xsl="&lt;a href="http://www.w3.org/1999/XSL/Transform"&gt;http://www.w3.org/1999/XSL/Transform&lt;/a&gt;"&lt;br /&gt;
xmlns:xs="&lt;a href="http://www.w3.org/2001/XMLSchema"&gt;http://www.w3.org/2001/XMLSchema&lt;/a&gt;"&lt;br /&gt;
xmlns:t="&lt;a href="http://www.nesterovsky-bros.com/xslt/public"&gt;http://www.nesterovsky-bros.com/xslt/public&lt;/a&gt;"&lt;br /&gt;
exclude-result-prefixes="t xs"&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:template match="/" name="main"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name="content"&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
&amp;lt;xsl:for-each select="1 to 3"&amp;gt;&lt;br /&gt;
&amp;lt;item/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:variable name="result"&amp;gt;&lt;br /&gt;
&amp;lt;root&amp;gt;&lt;br /&gt;
&amp;lt;xsl:for-each select="$content/root/item"&amp;gt;&lt;br /&gt;
&amp;lt;section-ref name-ref="&lt;span style="font-weight: bold"&gt;{t:generate-id()}.s&lt;/span&gt;"/&amp;gt;&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;lt;xsl:variable name="id" as="xs:string"&lt;br /&gt;
select="t:generate-id()"/&amp;gt;&lt;br /&gt;
&amp;lt;section-ref name-ref="{$id}.s"/&amp;gt;&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:for-each&amp;gt;&lt;br /&gt;
&amp;lt;/root&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:message select="$result"/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:template&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:function name="t:generate-id" as="xs:string"&amp;gt;&lt;br /&gt;
&amp;lt;xsl:variable name="element" as="element()"&amp;gt;&lt;br /&gt;
&amp;lt;element/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:variable&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;xsl:sequence select="generate-id($element)"/&amp;gt;&lt;br /&gt;
&amp;lt;/xsl:function&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/xsl:stylesheet&amp;gt; &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
This code performs some transformation and assigns unique values to &lt;code&gt;name-ref&lt;/code&gt; attributes.
Values generated with &lt;code&gt;t:generate-id()&lt;/code&gt; function are guaranteed to be unique,
as spec claims that every node has its unique &lt;code&gt;generate-id()&lt;/code&gt; value.
&lt;/p&gt;
&lt;p&gt;
Imagine, what was our surprise to find that generated elements all have the same &lt;code&gt;name-ref&lt;/code&gt;&amp;#39;s.
We studied code all over, and found no holes in our reasoning and implementation,
so our conlusion was: it&amp;#39;s Saxon&amp;#39;s bug!
&lt;/p&gt;
&lt;p&gt;
It&amp;#39;s interesting enough that if we rewrite code a little (see commented part),
it starts to work properly, thus we suspect Saxon&amp;#39;s optimizer.
&lt;/p&gt;
&lt;p&gt;
Well, in the course of development we have found and reported many Saxon bugs, but
how come that this little beetle was hiding so long.
&lt;/p&gt;
&lt;p&gt;
We&amp;#39;ve verified that the bug exists in the versions 9.2 and 9.3. Here is the bug
report: &lt;a href="http://sourceforge.net/projects/saxon/forums/forum/94027/topic/4621860"&gt; Saxon
9.2 generate-id() bug&lt;/a&gt;. 
&lt;/p&gt;
&lt;p&gt;
Unfortunatelly, it&amp;#39;s there already for three days (2011-07-25 to 2011-07-27) without
any reaction. We hope this will change soon.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=d653df7e-7503-4213-8546-290c3863f0e2" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,d653df7e-7503-4213-8546-290c3863f0e2.aspx</comments>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=c8b061fa-7471-4601-8b19-2c5bf55ce9ea</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c8b061fa-7471-4601-8b19-2c5bf55ce9ea.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=c8b061fa-7471-4601-8b19-2c5bf55ce9ea</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We did not update <a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"> languages-xom</a> already
for many monthes but now we have found a severe bug in the jxom's algorithm for eliminating
unreachable code. The marked line were considered as unreachable:
</p>
        <p style="padding-left: 1em">
          <code>check:<br />
if (condition)<br />
{<br />
break check;<br />
}<br />
else<br />
{<br />
return;<br />
}<br /><br />
// due to bug the following was considered unreachable<br /><span style="color: red; font-weight: bold">expression;</span></code>
        </p>
        <p>
Bug is fixed.
</p>
        <p>
Current update contains other cosmetic fixes. 
</p>
        <p>
Please download xslt sources from <a href="http://www.nesterovsky-bros.com/download/languages-xom.zip">languages-xom.zip</a>.
</p>
        <p>
Summary
</p>
        <p>
Languages XOM is a set of xml schemas and xslt stylesheets that allows:
</p>
        <ul>
          <li>
to define programs in xml form;</li>
          <li>
to perform transformations over code in xml form;</li>
          <li>
to generate sources.</li>
        </ul>
        <p>
Languages XOM includes:
</p>
        <ul>
          <li>
jxom - Java Xml Object model;</li>
          <li>
csharpxom - C# Xml Object Model;</li>
          <li>
cobolxom - COBOL Xml Object Model;</li>
          <li>
sqlxom - SQL Xml Object Model (including several sql dialects);</li>
          <li>
aspx - ASP.NET Object Model;</li>
        </ul>
        <p>
A proprietary part of languages XOM also includes XML Object Model for a language
named Cool:GEN. In fact the original purpose for this API was a generation of java/C#/COBOL
from Cool:GEN. For more details about Cool:GEN conversion please see <a href="http://www.bphx.com/en/Solutions/ApplicationModernization/Pages/CooLGen.aspx"> here</a>.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea" />
      </body>
      <title>Languages-XOM update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,c8b061fa-7471-4601-8b19-2c5bf55ce9ea.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/05/26/LanguagesXOMUpdate.aspx</link>
      <pubDate>Thu, 26 May 2011 05:15:11 GMT</pubDate>
      <description>&lt;p&gt;
We did not update &lt;a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"&gt; languages-xom&lt;/a&gt; already
for many monthes but now we have found a severe bug in the jxom's algorithm for eliminating
unreachable code. The marked line were considered as unreachable:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;check:&lt;br /&gt;
if (condition)&lt;br /&gt;
{&lt;br /&gt;
break check;&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
return;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// due to bug the following was considered unreachable&lt;br /&gt;
&lt;span style="color: red; font-weight: bold"&gt;expression;&lt;/span&gt; &lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Bug is fixed.
&lt;/p&gt;
&lt;p&gt;
Current update contains other cosmetic fixes. 
&lt;/p&gt;
&lt;p&gt;
Please download xslt sources from &lt;a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"&gt;languages-xom.zip&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Summary
&lt;/p&gt;
&lt;p&gt;
Languages XOM is a set of xml schemas and xslt stylesheets that allows:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
to define programs in xml form;&lt;/li&gt;
&lt;li&gt;
to perform transformations over code in xml form;&lt;/li&gt;
&lt;li&gt;
to generate sources.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Languages XOM includes:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
jxom - Java Xml Object model;&lt;/li&gt;
&lt;li&gt;
csharpxom - C# Xml Object Model;&lt;/li&gt;
&lt;li&gt;
cobolxom - COBOL Xml Object Model;&lt;/li&gt;
&lt;li&gt;
sqlxom - SQL Xml Object Model (including several sql dialects);&lt;/li&gt;
&lt;li&gt;
aspx - ASP.NET Object Model;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
A proprietary part of languages XOM also includes XML Object Model for a language
named Cool:GEN. In fact the original purpose for this API was a generation of java/C#/COBOL
from Cool:GEN. For more details about Cool:GEN conversion please see &lt;a href="http://www.bphx.com/en/Solutions/ApplicationModernization/Pages/CooLGen.aspx"&gt; here&lt;/a&gt;.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=c8b061fa-7471-4601-8b19-2c5bf55ce9ea" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,c8b061fa-7471-4601-8b19-2c5bf55ce9ea.aspx</comments>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5ed4531a-dbbb-48b5-89d2-b58d1ed78df8.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We have updated <code>@Yield</code> annotation processor to support better debug info.
</p>
        <p>
Annotation processor can be downloaded from <a href="http://www.nesterovsky-bros.com/download/java/Yield.zip">Yield.zip</a> or <a href="http://www.nesterovsky-bros.com/download/java/Yield.jar">Yield.jar</a>.
</p>
        <p>
We also decided to consider jxom's state machine refactoring as obsolete as <code>@Yield</code> annotation
allows to achieve the same effect but with more clear code.
</p>
        <p>
JXOM can be downloaded from <a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"> languages-xom.zip</a></p>
        <p>
See also: 
</p>
        <p>
          <a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx">Yield
return feature in java</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/2011/01/27/WhyYieldIteratorShouldBeCloseable.aspx">Why
@Yield iterator should be Closeable</a>
          <br />
          <a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx">What
you can do with jxom.</a>
        </p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8" />
      </body>
      <title>Java's @Yield return annotation update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,5ed4531a-dbbb-48b5-89d2-b58d1ed78df8.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/02/05/JavasYieldReturnAnnotationUpdate.aspx</link>
      <pubDate>Sat, 05 Feb 2011 21:12:05 GMT</pubDate>
      <description>&lt;p&gt;
We have updated &lt;code&gt;@Yield&lt;/code&gt; annotation processor to support better debug info.
&lt;/p&gt;
&lt;p&gt;
Annotation processor can be downloaded from &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.zip"&gt;Yield.zip&lt;/a&gt; or &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.jar"&gt;Yield.jar&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
We also decided to consider jxom&amp;#39;s state machine refactoring as obsolete as &lt;code&gt;@Yield&lt;/code&gt; annotation
allows to achieve the same effect but with more clear code.
&lt;/p&gt;
&lt;p&gt;
JXOM can be downloaded from &lt;a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"&gt; languages-xom.zip&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
See also: 
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2011/01/24/YieldReturnFeatureInJava.aspx"&gt;Yield
return feature in java&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2011/01/27/WhyYieldIteratorShouldBeCloseable.aspx"&gt;Why
@Yield iterator should be Closeable&lt;/a&gt;
&lt;br /&gt;
&lt;a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx"&gt;What
you can do with jxom.&lt;/a&gt; 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=5ed4531a-dbbb-48b5-89d2-b58d1ed78df8" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,5ed4531a-dbbb-48b5-89d2-b58d1ed78df8.aspx</comments>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,602f1d9d-bf21-4c55-86ef-c7d2ee403d6d.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,602f1d9d-bf21-4c55-86ef-c7d2ee403d6d.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p style="padding-left: 1em; font-style: italic">
          <a href="http://twitter.com/michaelhkay/statuses/32946749697953793">michaelhkay</a>:
Just posted a new internal draft of XSLT 3.0. Moving forward on maps, nested sequences,
and JSON support.
</p>
        <p>
Hope they will finally appear there!
</p>
        <p>
See also: <a href="http://www.nesterovsky-bros.com/weblog/2008/08/30/TuplesAndMapsNextTry.aspx">Tuples
and maps - next try</a>, <a href="http://www.nesterovsky-bros.com/weblog/2008/07/10/TuplesAndMapsStatusCLOSEDWONTFIX.aspx"> Tuples
and maps - Status: CLOSED, WONTFIX</a>, <a href="http://www.nesterovsky-bros.com/weblog/2008/05/18/TuplesAndMapsInSaxon.aspx"> Tuples
and maps in Saxon</a> and other blog posts on our site about immutable maps.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d" />
      </body>
      <title>Xslt 3.0 insights</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,602f1d9d-bf21-4c55-86ef-c7d2ee403d6d.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/02/03/Xslt30Insights.aspx</link>
      <pubDate>Thu, 03 Feb 2011 11:07:49 GMT</pubDate>
      <description>&lt;p style="padding-left: 1em; font-style: italic"&gt;
&lt;a href="http://twitter.com/michaelhkay/statuses/32946749697953793"&gt;michaelhkay&lt;/a&gt;:
Just posted a new internal draft of XSLT 3.0. Moving forward on maps, nested sequences,
and JSON support.
&lt;/p&gt;
&lt;p&gt;
Hope they will finally appear there!
&lt;/p&gt;
&lt;p&gt;
See also: &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/08/30/TuplesAndMapsNextTry.aspx"&gt;Tuples
and maps - next try&lt;/a&gt;, &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/07/10/TuplesAndMapsStatusCLOSEDWONTFIX.aspx"&gt; Tuples
and maps - Status: CLOSED, WONTFIX&lt;/a&gt;, &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/05/18/TuplesAndMapsInSaxon.aspx"&gt; Tuples
and maps in Saxon&lt;/a&gt; and other blog posts on our site about immutable maps.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=602f1d9d-bf21-4c55-86ef-c7d2ee403d6d" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,602f1d9d-bf21-4c55-86ef-c7d2ee403d6d.aspx</comments>
      <category>Thinking aloud</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=280d6e0d-1389-4566-9e0f-badef8530578</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,280d6e0d-1389-4566-9e0f-badef8530578.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,280d6e0d-1389-4566-9e0f-badef8530578.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=280d6e0d-1389-4566-9e0f-badef8530578</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
For some reason we never knew about instance initializer in java; on the other hand
static initializer is well known.
</p>
        <p style="padding-left: 1em;">
          <code> class A<br />
{<br />
int x;<br />
static int y;<br /><br />
// This is an instance initializer.<br />
{<br />
x = 1;<br />
}<br /><br />
// This is a static initializer.<br />
static<br />
{<br />
y = 2;<br />
}<br />
}</code>
        </p>
        <p>
Worse, we have missed it in the java grammar when we were building jxom. This way
jxom was missing the feature.
</p>
        <p>
Today we fix the miss and introduce a schema element:
</p>
        <p style="padding-left: 1em">
          <code>&lt;class-initializer static="boolean"&gt;<br />
&lt;block&gt;<br />
...<br />
&lt;/block&gt;<br />
&lt;/class-initializer&gt;</code>
        </p>
        <p>
It superseeds:
</p>
        <p style="padding-left: 1em">
          <code>&lt;static&gt;<br />
&lt;block&gt;<br />
...<br />
&lt;/block&gt;<br />
&lt;/static&gt;</code>
        </p>
        <p>
that supported static initializers alone.
</p>
        <p>
Please update <a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"> languages-xom
xslt stylesheets</a>.
</p>
        <p>
P.S. Out of curiosity, did you ever see any use of instance initializers?
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=280d6e0d-1389-4566-9e0f-badef8530578" />
      </body>
      <title>Java XML Object Model Update</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,280d6e0d-1389-4566-9e0f-badef8530578.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/01/14/JavaXMLObjectModelUpdate.aspx</link>
      <pubDate>Fri, 14 Jan 2011 21:29:04 GMT</pubDate>
      <description>&lt;p&gt;
For some reason we never knew about instance initializer in java; on the other hand
static initializer is well known.
&lt;/p&gt;
&lt;p style="padding-left: 1em;"&gt;
&lt;code&gt; class A&lt;br /&gt;
{&lt;br /&gt;
int x;&lt;br /&gt;
static int y;&lt;br /&gt;
&lt;br /&gt;
// This is an instance initializer.&lt;br /&gt;
{&lt;br /&gt;
x = 1;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is a static initializer.&lt;br /&gt;
static&lt;br /&gt;
{&lt;br /&gt;
y = 2;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Worse, we have missed it in the java grammar when we were building jxom. This way
jxom was missing the feature.
&lt;/p&gt;
&lt;p&gt;
Today we fix the miss and introduce a schema element:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;class-initializer static=&amp;quot;boolean&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;block&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/block&amp;gt;&lt;br /&gt;
&amp;lt;/class-initializer&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
It superseeds:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;&amp;lt;static&amp;gt;&lt;br /&gt;
&amp;lt;block&amp;gt;&lt;br /&gt;
...&lt;br /&gt;
&amp;lt;/block&amp;gt;&lt;br /&gt;
&amp;lt;/static&amp;gt;&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
that supported static initializers alone.
&lt;/p&gt;
&lt;p&gt;
Please update &lt;a href="http://www.nesterovsky-bros.com/download/languages-xom.zip"&gt; languages-xom
xslt stylesheets&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
P.S. Out of curiosity, did you ever see any use of instance initializers?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=280d6e0d-1389-4566-9e0f-badef8530578" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,280d6e0d-1389-4566-9e0f-badef8530578.aspx</comments>
      <category>Announce</category>
      <category>Java</category>
      <category>xslt</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=ebd5185f-fc37-4e82-b2bb-006387635512</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebd5185f-fc37-4e82-b2bb-006387635512.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebd5185f-fc37-4e82-b2bb-006387635512.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=ebd5185f-fc37-4e82-b2bb-006387635512</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
We could not stand the temptation to implement the <code>@Yield</code> annotation
that we described <a href="http://www.nesterovsky-bros.com/weblog/2010/12/20/YieldFeatureInJava.aspx">earlier</a>.
</p>
        <p>
Idea is rather clear but people are saying that it's not an easy task to update
the sources.
</p>
        <p>
They were right!
</p>
        <p>
Implementation has its price, as we were forced to access JDK's classes of javac
compiler. As result, at present, we don't support other compilers such as EclipseCompiler.
We shall look later what can be done in this area.
</p>
        <p>
At present, annotation processor works perfectly when you run javac either from the
command line, from ant, or from other build tool.
</p>
        <p>
Here is an example of how method is refactored:
</p>
        <p style="padding-left: 1em">
          <code>@Yield<br />
public static Iterable&lt;Long&gt; fibonachi()<br />
{<br />
ArrayList&lt;Long&gt; items = new ArrayList&lt;Long&gt;();<br /><br />
long Ti = 0;<br />
long Ti1 = 1;<br /><br />
while(true)<br />
{<br />
items.add(Ti);<br /><br />
long value = Ti + Ti1;<br /><br />
Ti = Ti1;<br />
Ti1 = value;<br />
}<br />
}</code>
        </p>
        <p>
And that's how we transform it:
</p>
        <p style="padding-left: 1em">
          <code>@Yield()<br />
public static Iterable&lt;Long&gt; fibonachi() {<br />
assert (java.util.ArrayList&lt;Long&gt;)(ArrayList&lt;Long&gt;)null == null : null;<br /><br />
class $state$ implements java.lang.Iterable&lt;Long&gt;, java.util.Iterator&lt;Long&gt;,
java.io.Closeable {<br /><br />
public java.util.Iterator&lt;Long&gt; iterator() {<br />
if ($state$id == 0) {<br />
$state$id = 1;<br />
return this;<br />
} else return new $state$();<br />
}<br /><br />
public boolean hasNext() {<br />
if (!$state$nextDefined) {<br />
$state$hasNext = $state$next();<br />
$state$nextDefined = true;<br />
}<br /><br />
return $state$hasNext;<br />
}<br /><br />
public Long next() {<br />
if (!hasNext()) throw new java.util.NoSuchElementException();<br /><br />
$state$nextDefined = false;<br /><br />
return $state$next;<br />
}<br /><br />
public void remove() {<br />
throw new java.lang.UnsupportedOperationException();<br />
}<br /><br />
public void close() {<br />
$state$id = 5;<br />
}<br /><br />
private boolean $state$next() {<br />
while (true) switch ($state$id) {<br />
case 0:<br />
$state$id = 1;<br />
case 1:<br />
Ti = 0;<br />
Ti1 = 1;<br />
case 2: 
<br />
if (!true) {<br />
$state$id = 4;<br />
break;<br />
}<br /><br />
$state$next = Ti;<br />
$state$id = 3;<br /><br />
return true;<br />
case 3: 
<br />
value = Ti + Ti1;<br />
Ti = Ti1;<br />
Ti1 = value;<br />
$state$id = 2;<br /><br />
break;<br />
case 4: 
<br />
case 5: 
<br />
default: 
<br />
$state$id = 5;<br /><br />
return false;<br />
}<br />
}<br /><br />
private long Ti;<br />
private long Ti1;<br />
private long value;<br />
private int $state$id;<br />
private boolean $state$hasNext;<br />
private boolean $state$nextDefined;<br />
private Long $state$next;<br />
}<br /><br />
return new $state$();<br />
}</code>
        </p>
        <p>
Formatting is automatic, sorry, but anyway it's for diagnostics only. You will
never see this code.
</p>
        <p>
It's iteresting to say that this implementation is very precisely mimics <a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx"> xslt
state machine implementation</a> we have done back in 2008.
</p>
        <p>
You can <a href="http://www.nesterovsky-bros.com/download/java/Yield.zip"> download
YieldProcessor here</a>. We hope that someone will find our solution very interesting.
</p>
        <img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512" />
      </body>
      <title>Yield feature in java implemented!</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,ebd5185f-fc37-4e82-b2bb-006387635512.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2011/01/11/YieldFeatureInJavaImplemented.aspx</link>
      <pubDate>Tue, 11 Jan 2011 16:08:41 GMT</pubDate>
      <description>&lt;p&gt;
We could not stand the temptation to implement the &lt;code&gt;@Yield&lt;/code&gt; annotation
that we described &lt;a href="http://www.nesterovsky-bros.com/weblog/2010/12/20/YieldFeatureInJava.aspx"&gt;earlier&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Idea is rather clear but people are saying that it&amp;#39;s not an easy task to update
the sources.
&lt;/p&gt;
&lt;p&gt;
They were right!
&lt;/p&gt;
&lt;p&gt;
Implementation has its price, as we were forced to access JDK&amp;#39;s classes of javac
compiler. As result, at present, we don&amp;#39;t support other compilers such as EclipseCompiler.
We shall look later what can be done in this area.
&lt;/p&gt;
&lt;p&gt;
At present, annotation processor works perfectly when you run javac either from the
command line, from ant, or from other build tool.
&lt;/p&gt;
&lt;p&gt;
Here is an example of how method is refactored:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;@Yield&lt;br /&gt;
public static Iterable&amp;lt;Long&amp;gt; fibonachi()&lt;br /&gt;
{&lt;br /&gt;
ArrayList&amp;lt;Long&amp;gt; items = new ArrayList&amp;lt;Long&amp;gt;();&lt;br /&gt;
&lt;br /&gt;
long Ti = 0;&lt;br /&gt;
long Ti1 = 1;&lt;br /&gt;
&lt;br /&gt;
while(true)&lt;br /&gt;
{&lt;br /&gt;
items.add(Ti);&lt;br /&gt;
&lt;br /&gt;
long value = Ti + Ti1;&lt;br /&gt;
&lt;br /&gt;
Ti = Ti1;&lt;br /&gt;
Ti1 = value;&lt;br /&gt;
}&lt;br /&gt;
}&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
And that&amp;#39;s how we transform it:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt;@Yield()&lt;br /&gt;
public static Iterable&amp;lt;Long&amp;gt; fibonachi() {&lt;br /&gt;
assert (java.util.ArrayList&amp;lt;Long&amp;gt;)(ArrayList&amp;lt;Long&amp;gt;)null == null : null;&lt;br /&gt;
&lt;br /&gt;
class $state$ implements java.lang.Iterable&amp;lt;Long&amp;gt;, java.util.Iterator&amp;lt;Long&amp;gt;,
java.io.Closeable {&lt;br /&gt;
&lt;br /&gt;
public java.util.Iterator&amp;lt;Long&amp;gt; iterator() {&lt;br /&gt;
if ($state$id == 0) {&lt;br /&gt;
$state$id = 1;&lt;br /&gt;
return this;&lt;br /&gt;
} else return new $state$();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public boolean hasNext() {&lt;br /&gt;
if (!$state$nextDefined) {&lt;br /&gt;
$state$hasNext = $state$next();&lt;br /&gt;
$state$nextDefined = true;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return $state$hasNext;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public Long next() {&lt;br /&gt;
if (!hasNext()) throw new java.util.NoSuchElementException();&lt;br /&gt;
&lt;br /&gt;
$state$nextDefined = false;&lt;br /&gt;
&lt;br /&gt;
return $state$next;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void remove() {&lt;br /&gt;
throw new java.lang.UnsupportedOperationException();&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
public void close() {&lt;br /&gt;
$state$id = 5;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private boolean $state$next() {&lt;br /&gt;
while (true) switch ($state$id) {&lt;br /&gt;
case 0:&lt;br /&gt;
$state$id = 1;&lt;br /&gt;
case 1:&lt;br /&gt;
Ti = 0;&lt;br /&gt;
Ti1 = 1;&lt;br /&gt;
case 2: 
&lt;br /&gt;
if (!true) {&lt;br /&gt;
$state$id = 4;&lt;br /&gt;
break;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
$state$next = Ti;&lt;br /&gt;
$state$id = 3;&lt;br /&gt;
&lt;br /&gt;
return true;&lt;br /&gt;
case 3: 
&lt;br /&gt;
value = Ti + Ti1;&lt;br /&gt;
Ti = Ti1;&lt;br /&gt;
Ti1 = value;&lt;br /&gt;
$state$id = 2;&lt;br /&gt;
&lt;br /&gt;
break;&lt;br /&gt;
case 4: 
&lt;br /&gt;
case 5: 
&lt;br /&gt;
default: 
&lt;br /&gt;
$state$id = 5;&lt;br /&gt;
&lt;br /&gt;
return false;&lt;br /&gt;
}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
private long Ti;&lt;br /&gt;
private long Ti1;&lt;br /&gt;
private long value;&lt;br /&gt;
private int $state$id;&lt;br /&gt;
private boolean $state$hasNext;&lt;br /&gt;
private boolean $state$nextDefined;&lt;br /&gt;
private Long $state$next;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
return new $state$();&lt;br /&gt;
}&lt;/code&gt; 
&lt;/p&gt;
&lt;p&gt;
Formatting is automatic, sorry, but anyway it&amp;#39;s for diagnostics only. You will
never see this code.
&lt;/p&gt;
&lt;p&gt;
It&amp;#39;s iteresting to say that this implementation is very precisely mimics &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx"&gt; xslt
state machine implementation&lt;/a&gt; we have done back in 2008.
&lt;/p&gt;
&lt;p&gt;
You can &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.zip"&gt; download
YieldProcessor here&lt;/a&gt;. We hope that someone will find our solution very interesting.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=ebd5185f-fc37-4e82-b2bb-006387635512" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,ebd5185f-fc37-4e82-b2bb-006387635512.aspx</comments>
      <category>Announce</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
      <category>Java</category>
    </item>
    <item>
      <trackback:ping>http://www.nesterovsky-bros.com/weblog/Trackback.aspx?guid=adb797fe-a781-423c-8dea-ea827d86241b</trackback:ping>
      <pingback:server>http://www.nesterovsky-bros.com/weblog/pingback.aspx</pingback:server>
      <pingback:target>http://www.nesterovsky-bros.com/weblog/PermaLink,guid,adb797fe-a781-423c-8dea-ea827d86241b.aspx</pingback:target>
      <dc:creator>Vladimir Nesterovsky</dc:creator>
      <georss:point>0 0</georss:point>
      <wfw:comment>http://www.nesterovsky-bros.com/weblog/CommentView,guid,adb797fe-a781-423c-8dea-ea827d86241b.aspx</wfw:comment>
      <wfw:commentRss>http://www.nesterovsky-bros.com/weblog/SyndicationService.asmx/GetEntryCommentsRss?guid=adb797fe-a781-423c-8dea-ea827d86241b</wfw:commentRss>
      <title>Yield feature in java</title>
      <guid isPermaLink="false">http://www.nesterovsky-bros.com/weblog/PermaLink,guid,adb797fe-a781-423c-8dea-ea827d86241b.aspx</guid>
      <link>http://www.nesterovsky-bros.com/weblog/2010/12/20/YieldFeatureInJava.aspx</link>
      <pubDate>Mon, 20 Dec 2010 16:28:35 GMT</pubDate>
      <description>&lt;p&gt;
Several times we have already wished to see &lt;a href="http://stackoverflow.com/questions/1980953/is-there-a-java-equivalent-to-cs-yield-keyword"&gt; &lt;code&gt;yield&lt;/code&gt; feature
in java&lt;/a&gt; and all the time came to the same implementation: &lt;a href="http://code.google.com/p/infomancers-collections/"&gt;infomancers-collections&lt;/a&gt;.
And every time with dissatisfaction turned away, and continued with regular iterators.
&lt;/p&gt;
&lt;p&gt;
Why? Well, in spite of the fact it's the best implementation of the feature we have
seen, it's still too heavy, as it's playing with java byte code at run-time.
&lt;/p&gt;
&lt;p&gt;
We never grasped the idea why it's done this way, while there is &lt;a href="http://download.oracle.com/javase/1.5.0/docs/guide/apt/GettingStarted.html"&gt;post-compile
time annotation processing in java&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
If we would implemented the yeild feature in java we would created a &lt;code&gt;@Yield&lt;/code&gt; annotation
and would demanded to implement some well defined code pattern like this:
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; @Yield&lt;br /&gt;
Iteratable&amp;lt;String&gt; iterator()&lt;br /&gt;
{ 
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
ArrayList&amp;lt;String&gt; list = new ArrayList&amp;lt;String&gt;();&lt;br /&gt;
&lt;br /&gt;&lt; 10; ++i)&lt;br /&gt;
for(int i = 0; i {&lt;br /&gt;
// list.add() plays the role of yield return.&lt;br /&gt;
list.add(String.valueOf(i));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
return list;&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
or
&lt;/p&gt;
&lt;p style="padding-left: 1em"&gt;
&lt;code&gt; @Yield&lt;br /&gt;
Iterator&amp;lt;String&gt; iterator()&lt;br /&gt;
{&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
ArrayList&amp;lt;String&gt; list = new ArrayList&amp;lt;String&gt;();&lt;br /&gt;
&lt;br /&gt;&lt; 10; ++i)&lt;br /&gt;
for(int i = 0; i {&lt;br /&gt;
// list.add() plays the role of yield return.&lt;br /&gt;
list.add(String.valueOf(i));&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// This is part of pattern.&lt;br /&gt;
return list.iterator();&lt;br /&gt;
} &lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;
Note that the code will work correctly even, if by mischance, post-compile-time processing
will not take place.
&lt;/p&gt;
&lt;p&gt;
At post comile time we would do all required refactoring to turn these implementations
into a state machines thus runtime would not contain any third party components.
&lt;/p&gt;
&lt;p&gt;
It's iteresting to recall that we have also implemented similar refactoring in pure
xslt.
&lt;/p&gt;
&lt;p&gt;
See &lt;a href="http://www.nesterovsky-bros.com/weblog/2008/09/05/WhatYouCanDoWithJxom.aspx" rel="bookmark"&gt;What
you can do with jxom&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
&lt;b&gt;Update:&lt;/b&gt; implementation can be found at &lt;a href="http://www.nesterovsky-bros.com/download/java/Yield.zip"&gt;Yield.zip&lt;/a&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.nesterovsky-bros.com/weblog/aggbug.ashx?id=adb797fe-a781-423c-8dea-ea827d86241b" /&gt;</description>
      <comments>http://www.nesterovsky-bros.com/weblog/CommentView,guid,adb797fe-a781-423c-8dea-ea827d86241b.aspx</comments>
      <category>Java</category>
      <category>Thinking aloud</category>
      <category>Tips and tricks</category>
      <category>xslt</category>
    </item>
  </channel>
</rss>