Monday, November 29, 2004

Implementing Group By in XSLT 

In order to group nodes in XSLT you need to create a key that will represent a common attribute for the nodes in a group.

Here is the code to do that. I always put this code in the root stylesheet node. This, may or may not be manadatory.


<xsl:key name="newgroupkey"
match="//nodeToGroup"
use="@groupingAttribute"/>


Next, you simply select a node group by using the generate-id() function and comparing it to the group key. Notice the reference to the first member of the array of nodes returned "[1]". The key comparison returns all members of each group so you need to select the first member of each node group in order to achieve the desired result.


<xsl:for-each select="//nodeToGroup[generate-id()=generate-id(key('newgroupkey',@groupingAttribute)[1])]">
<xsl:sort data-type="number" order="ascending" select="@groupingAttribute" />
<xsl:apply-templates select="." />
</xsl:for-each>


When you "apply-templates" to the selected node, you can use the @groupingAttribute to collect all the corresponding nodes in the same group for processing.

Friday, November 19, 2004

Fairly Precise HTML Layout 

In order to get my page layouts as close to my desired dimensions on the first try as possible I ran an experiment using IE and an HP printer, which is my typical environment, to find out what the ratio of Pixels to Inches is in this case.

I came up with approximately 95px per inch; 23px per .25 (1/4) inch; or a ratio of 5.9px per .0625 (1/16th) inches. This is good enough to get me close.

This page is powered by Blogger. Isn't yours?