Any good code highlighters for blogs?

Well, as I’m posting my tips here, I came across the problem with pasting programming code. Now I’m looking for a good online utility that would take code and HTML-escape it. It would be even better if it also did color-coding.

If I find something good, I’ll post a link here. For now, I’ll just be using a utility to escape all > and < entities. This is the first one I found in Google.

How to split a string with XSL

I needed to break a string like this “Hot Waffles,Fresh Fruits,Pastries,Bagels,Cereals,Muffins,Juices,Milk,Coffee” into separate XML elements. How to do it? Use a “tokenize” function!

<xsl:template name=”breakfast”>
<xsl:param name=”allItems”/>
<xsl:for-each select=”tokenize($allItems, ‘,’)”>
<item><xsl:value-of select=’.’/></item>
</xsl:for-each>
</xsl:template>

Result:

<item>Hot Waffles</item>
<item>Fresh Fruits</item>
<item>Pastries</item>
<item>Bagels</item>
<item>Cereals</item>
<item>Muffins</item>
<item>Juices</item>
<item>Milk</item>
<item>Coffee</item>

SQL Server: Delete in batches

When there’s a large amount of data to be deleted, the performance of SQL suffers a lot. One way around it is to delete in batches, for example 10 000 rows at a time.

Instead of :
delete from yourtable where [condition]

i’d use:

— set rowcount to delete sets of 10 000 records (use a smaller subset size if you think it’s better)
set rowcount 10000
— start delete
delete from yourtable where
while @@rowcount > 0 — loop until there’s no record left to delete
begin
— after each delete there will be an implicit commit
delete from yourtable where
end

Pass a command line parameter to an XSL stylesheet

It’s possible depending on the parser. And Saxon does support it!!!

1) Declare parameter in the stylesheet:

<xsl:param name="x"/> (XSLT version 1.0)

<xsl:param name="x" as="xs:integer" required="yes"/> (version 2.0)

2) Invoke Saxon as

java -jar saxon8.jar source.xml style.xsl x=Atlanta

In my example, I wanted to loop through the list of metro areas and create a separate raw file for each area using only one general fieldmapper XSL. And it worked!