Archive for February, 2009

Replacing text in XSL, the dirty way

February 24, 2009

Here the example replaces quotes with escaped quotes \”, but can be generalized.

First define a template:

<xsl:template name="cleanQuote">
<xsl:param name="string" />
<xsl:if test="contains($string, '"')">
<xsl:value-of select="substring-before($string, '"')" /> \"
<xsl:call-template name="cleanQuote">
<xsl:with-param name="string">
<xsl:value-of select="substring-after($string, '"')" />
<xsl:if test="not(contains($string, '"'))">
<xsl:value-of select="$string" />

Then use it at the appropriate point by calling:

<xsl:call-template name="cleanQuote">
<xsl:with-param name="string">
<xsl:value-of select="text" />


Statistics Textbook Online

February 19, 2009

This might be useful.

How do I read a huge file line by line in Python?

February 4, 2009

This is taken from here and was written by rupe.

In Python, the most common way to read lines from a file is to do the following:

for line in open('myfile','r').readlines():

When this is done, however, the readlines() function loads the entire file into memory as it runs. A better approach for large files is to use the fileinput module, as follows:

import fileinput
for line in fileinput.input(['myfile']):

the fileinput.input() call reads lines sequentially, but doesn’t keep them in memory after they’ve been read.