Thursday 23 January 2014

XSLT transformation to create newlines within a cell in a csv file

An issue with generating a newline within a spreadsheet when transforming an XML input to a csv file is that the newline character

<xsl:text>&#xa;</xsl:text>

creates a new row in the list.

To get around this use quote marks around the content of that cell:

<xsl:text>"</xsl:text>
      <xsl:value-of select="string-join(paths/path,'&#xa;')"/>
<xsl:text>"</xsl:text>

This example is converting a subversion log file to a csv and putting each changed file onto a newline within that particular cell

Friday 17 January 2014

Gmail Search Operators

has:attachment - returns all mail with attachments

size - returns messages for a specified size  - eg size:5m - returns messages of 5 Mb, size:512000 returns messages of 500 kb

larger -  returns messages larger than a specified size - eg larger:5m - also larger_than


smaller -  returns messages smaller than a specified size - eg smaller:5m - also smaller_than

older_than returns messages older than a specified time where y = year, m = month and d = day eg older_than:2y

newer_than returns messages newer than a specified time where y = year, m = month and d = day eg older_than:2y

has:userlabels - returns messages that have user-defined labels.

has:nouserlabels - returns messages that have no user-defined labels.

Saturday 4 January 2014

Word Counting in XSLT

A word count is easily determined within either a string or within the text nodes of an xml document.

To count the words within a string supplied in a variable $string:

 <xsl:sequence select="count(tokenize($string, '\W+')[. != ''])"/>

To do the same for the whole XML document use:

<xsl:template match="/">
 <xsl:sequence select="count(//text()/tokenize(., ’\W+’)[.!=’’])"/>
</xsl:template>

To count the words within the text nodes of an xml document and sort them based upon the word frequency, use this:

<xsl:template match="/">
<xsl:for-each-group group-by="." select="for $word in //text()/tokenize(., ’\W+’)[.!=’’] return lower-case($word)">
 <xsl:sort select="count(current-group())" order="descending"/>
 <word word="{current-grouping-key()}"
  frequency="{count(current-group())}"/>
</xsl:for-each-group>
</xsl:template>