<?xml version="1.0" encoding="utf-8"?>
			
			<rss version="2.0">
			<channel>
			<title>Wayne Graham&apos;s Blog - XSLT</title>
			<link>http://swem.wm.edu/blogs/waynegraham/index.cfm</link>
			<description>ColdFusion Development for Academic Libraries</description>
			<language>en-us</language>
			<pubDate>Sun, 22 Nov 2009 17:03:34 -0500</pubDate>
			<lastBuildDate>Wed, 23 Aug 2006 11:56:00 -0500</lastBuildDate>
			<generator>BlogCFC</generator>
			<docs>http://blogs.law.harvard.edu/tech/rss</docs>
			<managingEditor>wsgrah@wm.edu</managingEditor>
			<webMaster>wsgrah@wm.edu</webMaster>
			
			
			
			
			
			<item>
				<title>Real Life XSLT 2.0 transformations</title>
				<link>http://swem.wm.edu/blogs/waynegraham/index.cfm/2006/8/23/Real-Life-XSLT-20-transformations</link>
				<description>
				
				I ran into a bit of a situation that was really blowing my mind. I have a rather large XML file (around 20,000+ lines) marked up in TEI that I wanted to do some transformations on (a day book and ledger from the 1850s). Essentially the code follows the format

&lt;code&gt;
...
&lt;figure&gt;
	&lt;head&gt;Page 12&lt;/head&gt;
	&lt;graphic url=&quot;0023_p12&quot;/&gt;
&lt;/figure&gt;

&lt;fw type=&quot;header&quot; place=&quot;top-center&quot;&gt;
	&lt;name type=&quot;place&quot; key=&quot;7022220&quot;&gt;Williamsburg&lt;/name&gt;,
	&lt;date value=&quot;1850&quot;&gt;1850&lt;/date&gt;,
&lt;/fw&gt;

&lt;table&gt;
	&lt;row&gt;
		&lt;cell&gt;
			&lt;date value=&quot;1850-10-03&quot;&gt;&lt;choice&gt;&lt;abbr&gt;Oct&lt;hi rend=&quot;sup;underline&quot;&gt;r&lt;/hi&gt;&lt;/abbr&gt;&lt;expan&gt;October&lt;/expan&gt;&lt;/choice&gt; 3&lt;hi rend=&quot;sup&quot;&gt;th&lt;/hi&gt; 1850&lt;/date&gt;
		&lt;/cell&gt;
		&lt;cell&gt;
			&lt;name type=&quot;person&quot; key=&quot;griffss01&quot;&gt;Doct&lt;hi rend=&quot;sup;underline&quot;&gt;r&lt;/hi&gt; S S Griffin&lt;/name&gt;
		 &lt;/cell&gt;
		 &lt;cell&gt;&amp;nbsp;&lt;/cell&gt;
	&lt;/row&gt;
	...
&lt;/table&gt;
&lt;pb/&gt;
...
&lt;/code&gt;

What I wanted to accomplish was group all this together in separate divs for HTML output (ok, I actually need to write each page to its own file, but this is pretty much just one more step). 

I just could not find a way to group this info this way using XSLT 1 without wrapping each page within its own div structure. I didn&apos;t really want to go back and do this, so I asked the TEI-L list. David Sewell pinged me back with some XQuery code that recursively recalls the document structure for a given node. 

He also mentioned that it would be pretty easy to write an XSLT 2 transformation that groups these nodes together. I did a little bit of digging and came up with

&lt;code&gt;
&lt;xsl:template match=&quot;tei:div&quot;&gt;
	&lt;xsl:for-each-group select=&quot;*&quot; group-ending-with&quot;tei:pb&quot;&gt;
		&lt;div class=&quot;page&quot;&gt;
			 &lt;xsl:apply-templates select=&quot;current-group()&quot; /&gt;
		&lt;/div&gt;
	&lt;/xsl:for-each-group&gt;
&lt;/xsl:template&gt;
&lt;/code&gt;

This transformed the pages to what I was wanting

&lt;code&gt;
&lt;div class=&quot;page&quot;&gt;
	&lt;img src=&quot;0023_12.png&quot; alt=&quot;Page 12&quot; /&gt;
	
	&lt;h1 class=&quot;fw&quot;&gt;Williamsburg, 1850,&lt;/h1&gt;
	
	&lt;table&gt;
		&lt;tr&gt;
			&lt;td&gt;
			&lt;span class=&quot;abbr&quot;&gt;Oct&lt;sup&gt;&lt;u&gt;r&lt;/u&gt;&lt;/sup&gt;&lt;/span&gt;&lt;span class=&quot;expan&quot;&gt;October&lt;/span&gt; 3&lt;sup&gt;th&lt;/sup&gt; 1850&lt;/date&gt;
		&lt;/td&gt;
		&lt;td&gt;
			&lt;a href=&quot;javascript:getName(&apos;griffss01&apos;);&gt;Doct&lt;sup&gt;&lt;u&gt;r&lt;/u&gt;&lt;/sup&gt; S S Griffin&lt;/a&gt;
		 &lt;/td&gt;
		 &lt;td&gt;&amp;nbsp;&lt;/td&gt;
	&lt;/row&gt;
	...
&lt;/table&gt;
&lt;/div&gt;

&lt;div class=&quot;page&quot;&gt;
	...
&lt;/div&gt;
&lt;/code&gt;

The XSLT processor for ColdFusion doesn&apos;t support XSLT 2.0 (it&apos;s still a draft spec). However, Saxon does (specifically Saxon 8). For more on doing XSLT transformations, see &lt;a href=&quot;http://swem.wm.edu/blogs/waynegraham/index.cfm/2005/11/21/XSLT-20-in-ColdFusion&quot;&gt;XSLT 2.0 in ColdFusion&lt;/a&gt;.
				
				</description>
						
				
				<category>XSLT</category>				
				
				<category>Web</category>				
				
				<category>ColdFusion</category>				
				
				<category>XML</category>				
				
				<pubDate>Wed, 23 Aug 2006 11:56:00 -0500</pubDate>
				<guid>http://swem.wm.edu/blogs/waynegraham/index.cfm/2006/8/23/Real-Life-XSLT-20-transformations</guid>
				
			</item>
			
		 	
			</channel></rss>