[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: [XSL] extracting a verse

Subject: Re: [XSL] extracting a verse
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 18 Dec 2002 20:48:52 -0500
disable output escaping verse
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">&lt;verse></xsl:text>
  <xsl:for-each select="ancestor::*[ancestor::quote]">
    <xsl:text disable-output-escaping="yes">&lt;</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">&lt;verse></xsl:text>
<xsl:for-each select="ancestor::*[ancestor::quote]">
<xsl:text disable-output-escaping="yes">&lt;</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">&lt;/</xsl:text>
<xsl:value-of select="name()"/>
<xsl:text disable-output-escaping="yes">></xsl:text>
</xsl:for-each>
<xsl:text disable-output-escaping="yes">&lt;/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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.