Re: [xsl] [XSL] extracting a verse

Subject: Re: [xsl] [XSL] extracting a verse
From: "Michael H. Semcheski" <mhs-list@xxxxxxxxx>
Date: Wed, 18 Dec 2002 14:26:37 -0500
I started thinking about this, and I think I have an approach somewhere in between the JITT and the BUVH. Its pretty simple, actually, so I am wondering if there is a reason that this didn't already come up. I can't really play around with it anymore, but this might be a step...

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:template match="/quote">
<xsl:for-each select="verse">
<xsl:call-template name="showverse">
<xsl:with-param name="vcont" select="."></xsl:with-param>
</xsl:call-template>
</xsl:for-each>
</xsl:template>


<xsl:template name="showverse">
<xsl:param name="vcont"/>
<xsl:call-template name="nextsib">
<xsl:with-param name="csib" select="following::*"/>
</xsl:call-template><hr/>
</xsl:template>
<xsl:template name="nextsib">
<xsl:param name="csib"/>
<xsl:value-of select="$csib[1]"/>
<xsl:if test="name($csib[1])!='endVerse'">
<xsl:call-template name="nextsib">
<xsl:with-param name="csib" select="$csib/descendant::*"/>
</xsl:call-template>
<xsl:if test="not($csib/descendant::endVerse)">
<xsl:call-template name="nextsib">
<xsl:with-param name="csib" select="$csib/following::*"/>
</xsl:call-template>
</xsl:if>
</xsl:if>
</xsl:template>
</xsl:stylesheet>



One approach is to go "bottom up". This is what Patrick Durusau and Matthew O'Donnell, who (AFAIK) have done the most work in public with this problem, call a "bottom-up virtual hierarchy" (BUVH). One pass flattens *everything* into milestones; the second interpolates the hierarchy you want. (Actually this is a simplification of what they did, though I don't see why it wouldn't work.) This is doable, but quite hairy if you want to preserve any of the original hierarchy, and so processor intensive that you don't want to be trying it on large texts. More lately, their efforts have shifted to an approach they call JITTs ("Just-in-Time Trees"), in which the verse starts and ends are promoted from atomic milestones into real element starts and ends. (A pre-XML-parse process then extracts the hierarchy you want.) While charmingly enunciated, and (I believe) ultimately on the right track, this approach suffers (IMHO) because it tries to repeal the First Law of XML Markup: "Thou Shalt be Cleanly Nested", thereby risking unnecessary Uncertainty and Doubt, if not actually Fear.




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread