David,
At 07:57 PM 12/18/2002, you wrote:
I missed the start of this thread but is d-o-e acceptable?
It is, if you allow that you're making the XSLT processor drive a fancy
string-writing routine (here based on a tree walk), rather than doing a
"proper" tree transformation.
As you know better than anyone, David. :->
Whether the original poster (was it Michael?) can solve his problem by
generating strings with a serializer, I can't say. (There are those, I
hear, who believe a mere string can hardly amount to XML, and shouldn't be
allowed to be processed by a computer at least unescorted).
I note also the transformation has to know the element type of the
outermost wrapper, here <quote>...</quote> (though I suppose this could be
handled in other ways too).
It *is* an ingenious approach (and requires a breakthrough, as I expected),
and (I have no doubt) will be often resorted to (with its variations). It
may even be a second reasonable use of d-o-e.
The next thing wanted will be some alignment, so that successive <seg>
elements, say, keep track of which other segs they belong to. I suppose you
do this by faking an attribute that points to the parent, as in
<xsl:template match="*">
<xsl:copy>
<xsl:attribute name="id">
<xsl:value-of select="generate-id()"/>
</xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="verse">
<xsl:text disable-output-escaping="yes"><verse></xsl:text>
<xsl:for-each select="ancestor::*[ancestor::quote]">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes"> align="</xsl:text>
<xsl:value-of select="generate-id(..)"/>
<xsl:text disable-output-escaping="yes">"></xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="endVerse">... as you have it ...</xsl:template>
Admiringly,
Wendell
If so it seems fairly easy, something like
...
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="verse">
<xsl:text disable-output-escaping="yes"><verse></xsl:text>
<xsl:for-each select="ancestor::*[ancestor::quote]">
<xsl:text disable-output-escaping="yes"><</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:for-each>
</xsl:template>
<xsl:template match="endVerse">
<xsl:for-each select="ancestor::*[ancestor::quote]">
<xsl:sort select="-count(ancestor::*)" data-type="number"/>
<xsl:text disable-output-escaping="yes"></</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:for-each>
<xsl:text disable-output-escaping="yes"></verse></xsl:text>
</xsl:template>
</xsl:stylesheet>
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
___&&__&_&___&_&__&&&__&_&__&__&&____&&_&___&__&_&&_____&__&__&&_____&_&&_
"Thus I make my own use of the telegraph, without consulting
the directors, like the sparrows, which I perceive use it
extensively for a perch." -- Thoreau
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list