Thursday 30 December 2010

Applying XSLT template rules to strings / matching strings

I extremely like template rules in XSLT (I miss them much in XQuery). But it's impossible to match on simple types, only on nodes.
Solution is trivial - use xsl:value-of to construct text node, which can be matched:


  <xsl:variable name="text">

  <xsl:variable as="text()*" name="words">
    <xsl:for-each select="tokenize( normalize-space(.), ' ' )">
      <xsl:value-of select="."/>
    </xsl:for-each>
  </xsl:variable>

<xsl:template match="text()[ starts-with(.,'A') ]" mode="word">
  <A>
    <xsl:copy-of select="."/>
  </A>
</xsl:template>



A very simple and trivial thing, but took some time for me to figure out - writing it here mostly for myself - not to forget.

Monday 4 October 2010

XQJ: binding document or sequence in pipeline

Bad thing from Cocoon / SAX pipeline point of view.
I found no way to bind SAX events effectively. Two options are available:

  • SAXSource - you must buffer events and then send them out on parse() method on XMLReader.
  • Provide StAX stream.

Both require buffering of SAX events, which can be a trouble in case of large XMLs. It kills all the elegancy and small memory foot-print.

An alternative would be to use StAX pipelines, which makes XSLT for example less effective.

I hope I mess something in docs, but...


So I must abandon the idea of using XQJ with C3 and Sedna for a moment, additional reasons: Sedna doesn't support latest XQuery things XQJ is good for and available XQJ implementation has closed source.
I switch back to default Sedna API.

TinyOS smells even better than I suspected : TUnit

#define assertEquals(msg, expected, actual)\
  if ((expected) != (actual)) {\
    assertEqualsFailed(msg, ((uint32_t) expected), ((uint32_t) actual), unique(UQ_ASSERTION));\
  } else {\
    assertSuccess();\
  }


So this is some holiday!
expected and actual are evaluated twice!
If you put this macro inside some if-else without nesting in {} you will get very funny things!


Why not:

#define assertEquals(msg, expected, actual) ({\
uint32_t e = expected;\
uint32_t a = actual;\
  if (a != e) {\
    assertEqualsFailed(msg, e, a, unique(UQ_ASSERTION));\
  } else {\
    assertSuccess();\
  }\
})


Why?!

How to fix it? - use Contiki.

Thursday 23 September 2010

Good and pitty things about Sedna 3.3

Charles Foster implemented and XQJ API for Sedna - http://www.cfoster.net/sedna/xqj/
I made initial Cocoon3 components wrapping it, perfomance to be analyzed.
XQuery external variables can be used easily and loaded from streams/URLs.

And it would be natural to use XQuery update with external variable, ala:
declare variable $x external;
for $a in $x/a
return

    if( ... )
    then(
        insert
             ...
        into collection('aaa')/a[ id = $a/id ]
    )
    else (
        replace  ...

    )
It promises clear perfomance gains - parsed once in Sedna, no Java parsing-serialization.

And here comes pitty thing Sedna 3.3 doesn't supported "nested updates" - update can be only one and at the top of query. Ofcourse you can do some tricks still, but pitty.

Sedna team promises to implement XQuery update facility, but no timeline.

Anyway, I do not think this small thing will switch me to another XML DB :)

Thursday 9 September 2010

Found smaller bug in NesC

Funny, suppose we have:

typedef struct 
{
    int a;
}strukt;


interface I
{
    command strukt func();
}

then
    call I.func().a 
doesn't work, it try to call "I.func().a", but
    (call I.func()).a 
helps :)

This call is strange indeed, main thing it is absolutely unneeded.

Common answer is - do not use TinyOS, it is too much a set of degree and diploma works, too less usable.

Tuesday 27 July 2010