If you're interested in functional programming, you might also want to checkout my second blog which i'm actively working on!!

Tuesday, June 28, 2011

Finished some restyling of this blog

Ok.. I just received news of Google's +1 button which is kinda cool to get noticed so I decided to hack it in. Because i again played around with the template designer of my blog my previous customizations got lost. Nothing to worry really, only SyntaxHighLighter was not working anymore and my code snippets magically vanished. So I decided to switch to using the latest and greatest version of SyntaxHighLighter and use the autoloader which was a new feature. I also am using the hosted version of the css and js files which is easier.

One side note: I had to make sure syntaxhighlighter got bootstrapped only after the dom was loaded. So I used YUI3's onDomReady event to call a bootstrapSyntaxHighLighter function i wrote.

Tuesday, June 14, 2011

Mimicking the Switch Expression in XQuery1.0

Here follows a little trick I picked up. Sometimes you want just like in many other programming languages to handle several use cases depending on a switch expression. This is not possible for XQuery1.0 by default but that does not mean you can't mimic it using the typeswitch expression ;-)



Output:

Complex Grouping with Xquery ...the general pattern

Testdata:


The idea is that we group all items so we get combinations of chapter with resp. paragraphs. However, some paragraphs don't have a parent (chapter). In this case those paragraphs should be handled first.


Expected output:


Well, here is kind of a generic solution (read solution pattern). You need 1 function that extracts the groupingkey from an item. The getGroupingKeys function just takes the distinct values of all grouping keys. So when you have the groupingkeys, you can determine the items belonging to each group using this predicate [local:getGroupingKey(.) = $grouping_key]. Next you handle the items for each group the way you want.

Generic Join function (XSLT/ Xquery)

In case you need a very high level join function for a sequence of items, I just wrote one which works very nicely.