xsl-list
[Top] [All Lists]

Re: How recursively iterate over entire document?

2005-08-15 12:10:14
Kenneth,

At 12:30 PM 8/13/2005, you wrote:
Wendell,

    What is micropipelining?

That's a name for the (emerging) idiom of binding a transformation result to a variable and then processing that as input. Classically this is done on the entire source document at once, through a "pipeline" of transformations. But in XSLT 2.0 (and in 1.0 using the node-set() extension) it can be done on just snippets or pieces of a document at once.

So for example, I had a case where I wanted a new element, w:caption, to have the same semantics as a nested combination of other elements ... that is

<picture id="schmidt-cover" frame="distinctive" width="120"
  source="schmidt-cover.jpg">
  <caption frame="caption" style="caption" x="0" y="175" width="165">
    <line line-height="10"><i>Hall&apos;s Military
     Breechloaders</i></line>
     <line>Peter A Schmidt, 1996</line>
     <line>Andrew Mowbray Publishers</line>
     <line>PO Box 460 Lincoln RI 02865 USA</line>
     <line>ISBN 0-917218-73-6</line>
  </caption>
</picture>

was to work exactly the same as (while being slightly easier to code than)

<picture id="schmidt-cover" frame="distinctive" width="120"
  source="schmidt-cover.jpg"/>

<hide id="schmidt-cover-caption"
  show-when="schmidt-cover.click" hide-when="schmidt-cover-caption.click">
  <panel frame="caption" style="caption"
    x="0" y="175" width="165">
    <line line-height="10"><i>Hall&apos;s Military
      Breechloaders<:i></line>
    <line>Peter A Schmidt, 1996</line>
    <line>Andrew Mowbray Publishers</line>
    <line>PO Box 460 Lincoln RI 02865 USA</line>
    <line>ISBN 0-917218-73-6</line>
  </panel>
</hide>

Rather than duplicate all the code, or encapsulate the code for 'panel' in a place where 'caption' could get access to it, I decided simply to take the panel code as the normative version, and declare the caption to be merely a special variant. So (in XSLT 2.0) I could say

  <xsl:template match="wgll:caption">
    <xsl:variable name="picture-id" select="parent::wgll:picture/@id"/>
    <xsl:variable name="caption-panel">
      <wgll:hide id="{$picture-id}-caption"
show-when="{$picture-id}.click" hide-when="{$picture-id}-caption.click">
        <wgll:panel>
          <xsl:copy-of select="@*"/>
          <xsl:copy-of select="node()"/>
        </wgll:panel>
      </wgll:hide>
    </xsl:variable>
    <xsl:apply-templates select="$caption-panel"/>
  </xsl:template>

The "micropipeline" is in the two-stage process: first, convert to something you already know how to process; second, process it.

I still don't know, however, if this is good application design. Probably perfectly fine, I suppose, so long as it's documented (eheh).

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--