<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Kookerella</title><link>https://kookerella.com/</link><description>Recent content on Kookerella</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sat, 15 Jun 2024 00:00:00 +0000</lastBuildDate><atom:link href="https://kookerella.com/index.xml" rel="self" type="application/rss+xml"/><item><title>Functional XSLT/XPath/XQuery - #5 Monad pattern</title><link>https://kookerella.com/posts/functional-xsltxpathxquery-5-monad-pattern/</link><pubDate>Sat, 15 Jun 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/functional-xsltxpathxquery-5-monad-pattern/</guid><description>&lt;h1 id="functional-xsltxpathxquery---5-monad-pattern">Functional XSLT/XPath/XQuery - #5 Monad pattern&lt;/h1>
&lt;p>The monad is probably the most written about functional pattern, it is famous for convoluted and obtuse explanations, but I will steal some of the better explanations and translate them into XSLT/XPath.&lt;/p>
&lt;p>(adapted directly from &lt;a href="https://wiki.haskell.org/All_About_Monads">All About Monads - HaskellWiki&lt;/a>).&lt;/p>
&lt;p>&amp;ldquo;Suppose that we are writing a program to keep track of sheep cloning experiments. We would certainly want to know the genetic history of all of our sheep, so we would need &lt;code>mother&lt;/code> and &lt;code>father&lt;/code> functions. But since these are cloned sheep, they may not always have both a mother and a father!&lt;/p></description></item><item><title>Functional XSLT/XPath/XQuery - #4 Monoid</title><link>https://kookerella.com/posts/functional-xsltxpathxquery-4-monoid/</link><pubDate>Sun, 09 Jun 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/functional-xsltxpathxquery-4-monoid/</guid><description>&lt;h1 id="functional-xsltxpathxquery---4-monoid">Functional XSLT/XPath/XQuery - #4 Monoid&lt;/h1>
&lt;p>Usually in these sorts of tutorials Monoid comes first, its the simplest, easiest most familiar sort of thing, we don&amp;rsquo;t really even need code to describe it, its loosely the theory of having something you can composing two things together and getting another thing of the same type, together with an identity element, so in mathematics the integers form a monoid with &lt;code>+&lt;/code> and the identity element is &lt;code>0&lt;/code> or we can use multiplication &lt;code>*&lt;/code> and &lt;code>1&lt;/code>, the set of booleans, i.e. &lt;code>{ True , False }&lt;/code> together with the operator &lt;code>AND&lt;/code> form a monoid, where the identity element is &lt;code>True&lt;/code>, to be honest, these things are rarely used as monoids in functional code, they could be, there just isn&amp;rsquo;t much use, the things that are usually used as monoids are collections, so in the XPath world this is &lt;code>sequence&lt;/code>, &lt;code>array&lt;/code>, &lt;code>map&lt;/code> (and the recently added &lt;code>maybe&lt;/code>).&lt;/p></description></item><item><title>Functional XSLT/XPath/XQuery - #3 Maybe data type</title><link>https://kookerella.com/posts/functional-xsltxpathxquery-3-maybe-data-type/</link><pubDate>Wed, 05 Jun 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/functional-xsltxpathxquery-3-maybe-data-type/</guid><description>&lt;h1 id="functional-xsltxpathxquery---3-maybe-data-type">Functional XSLT/XPath/XQuery - #3 Maybe data type&lt;/h1>
&lt;p>We are now in a position to fill in a missing data type.&lt;/p>
&lt;p>Lets cover some XPath basics.&lt;/p>
&lt;p>Consider the following XSLT&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;">&lt;code class="language-xml" data-lang="xml">&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">&amp;lt;xsl:stylesheet&lt;/span> &lt;span style="color:#a6e22e">xmlns:xsl=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;http://www.w3.org/1999/XSL/Transform&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">exclude-result-prefixes=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;#all&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">version=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;3.0&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">xmlns:xs=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;http://www.w3.org/2001/XMLSchema&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">xmlns:kooks=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;http://kookerella.com&amp;#34;&lt;/span>&lt;span style="color:#f92672">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:output&lt;/span> &lt;span style="color:#a6e22e">method=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;xml&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">indent=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;yes&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:function&lt;/span> &lt;span style="color:#a6e22e">name=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;kooks:safeDivision&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">as=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;xs:numeric?&amp;#34;&lt;/span>&lt;span style="color:#f92672">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:param&lt;/span> &lt;span style="color:#a6e22e">name=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;numerator&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">as=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;xs:numeric&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span> 
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:param&lt;/span> &lt;span style="color:#a6e22e">name=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;denominator&amp;#34;&lt;/span> &lt;span style="color:#a6e22e">as=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;xs:numeric&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:if&lt;/span> &lt;span style="color:#a6e22e">test=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;not($denominator eq 0)&amp;#34;&lt;/span>&lt;span style="color:#f92672">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:sequence&lt;/span> &lt;span style="color:#a6e22e">select=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;$denominator div $denominator&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;/xsl:if&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;/xsl:function&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:template&lt;/span> &lt;span style="color:#a6e22e">match=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;/&amp;#34;&lt;/span>&lt;span style="color:#f92672">&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;output&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:variable&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">name=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;calculations&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">as=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;xs:numeric*&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#a6e22e">select=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;(1 div 1,1 div 2,2 div 3)&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;xsl:sequence&lt;/span> &lt;span style="color:#a6e22e">select=&lt;/span>&lt;span style="color:#e6db74">&amp;#34;$calculations&amp;#34;&lt;/span>&lt;span style="color:#f92672">/&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;/output&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span> &lt;span style="color:#f92672">&amp;lt;/xsl:template&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;span style="display:flex;">&lt;span>&lt;span style="color:#f92672">&amp;lt;/xsl:stylesheet&amp;gt;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>If we execute it against an xml it returns this:&lt;/p></description></item><item><title>Functional XSLT/XPath/XQuery - #1 Introduction</title><link>https://kookerella.com/posts/functional-xsltxpathxquery-1-introduction/</link><pubDate>Mon, 03 Jun 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/functional-xsltxpathxquery-1-introduction/</guid><description>&lt;h1 id="functional-xsltxpathxquery---1-introduction">Functional XSLT/XPath/XQuery - #1 Introduction&lt;/h1>
&lt;p>To the modern programmer these languages appear strange beasts, born when the world was obsessed with XML, it is declarative, almost functional, but somehow missing some of the idioms of later more consciously functional languages. For a functional programmer it misses familiar function and data types that the functional programmer instinctively expect. To be fair their roots predate much of the flowering of functional patterns in language development and whilst the semantics of the languages are quite well suited to this style of development, the foundations are idiosyncratic, and now locked in by their history to be slightly out of step.&lt;/p></description></item><item><title>Functional XSLT/XPath/XQuery - #2 Functor pattern</title><link>https://kookerella.com/posts/functional-xsltxpathxquery-2-functor/</link><pubDate>Mon, 03 Jun 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/functional-xsltxpathxquery-2-functor/</guid><description>&lt;h1 id="functional-xsltxpathxquery---2-functor-pattern">Functional XSLT/XPath/XQuery - #2 Functor pattern&lt;/h1>
&lt;p>In the previous blog we introduced some machinery, the id function, and function composition, we talked about function types, and invented an informal notion of parametric types in order to aid our thinking.&lt;/p>
&lt;p>We now move onto the functional patterns. These are a bit like OO patterns but have more formal mathematical underpinnings. Knowing what to call the things is problematic in itself, in mathematics these underpinnings are called a &lt;em>category,&lt;/em> in functional circles they are often called a &lt;em>typeclass ,&lt;/em> this is a borrowed term from Haskell that has a particular mechanism for implementing them which may be misleading, other languages have different mechanisms, some languages have no formal mechanism, but have informal mechanisms, or no mechanism at all apart from idiomatic usage, like an OO pattern.&lt;/p></description></item><item><title>Dependency injection in XSLT...or actually maybe not</title><link>https://kookerella.com/posts/dependency-injection-in-xsltor-actually-maybe-not/</link><pubDate>Wed, 08 May 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/dependency-injection-in-xsltor-actually-maybe-not/</guid><description>&lt;h1 id="dependency-injection-in-xsltor-actually-maybe-not">Dependency injection in XSLT&amp;hellip;or actually maybe not&lt;/h1>
&lt;p>Ever written two, three or more stylesheets that are almost the same, but not quite the same, maybe you&amp;rsquo;ve struggled with #import or #include to separate your core shared code from the bespoke specific code? Maybe you&amp;rsquo;re an OO programmer steeped in the theology of objects, favouring composition over inheritance and find XSLT innate mechanisms to close to its OO cousins? Or a functional programmer at ease with higher order functions, but dabbling in some XSLT and wondering how to apply you functional skills, well read on, hopefully this blog will help you apply these skills in XSLT but ironically question whether these techniques really are the &amp;ldquo;state of the art&amp;rdquo;, many believe and when you return to your Scala/C#/Java/C++ or whatever it is you do most of the time, question whether there is more than one way to skin the cat (ew&amp;hellip;I hate that phrase).&lt;/p></description></item><item><title>Producing JSON in XSLT, a simple walkthrough.</title><link>https://kookerella.com/posts/producing-json-in-xslt-a-simple-walkthrough/</link><pubDate>Wed, 08 May 2024 00:00:00 +0000</pubDate><guid>https://kookerella.com/posts/producing-json-in-xslt-a-simple-walkthrough/</guid><description>&lt;h1 id="producing-json-in-xslt-a-simple-walkthrough">Producing JSON in XSLT, a simple walkthrough.&lt;/h1>
&lt;p>XSLT isnt just for XML, it can, surprisingly transform from and to JSON, but simple tutorials seem thin on the ground, what follows is a walkthough of of how to generate a simple JSON output.&lt;/p></description></item><item><title>CsExcel</title><link>https://kookerella.com/products/csexcel/</link><pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate><guid>https://kookerella.com/products/csexcel/</guid><description>A C# wrapper around FsExcel for writing Excel workbooks via ClosedXML, using a flat, declarative list of instructions.</description></item></channel></rss>