xsl-list
[Top] [All Lists]

Re: How to output open/close tags independently?

2002-12-26 16:23:43
I don't see what the connection is between trying to coerce XSLT into accepting 
non-well-formed markup, and grouping.
As others have pointed out, the FAQ gives a good example of how to group by a 
fixed number of elements.  For grins, I took your sample and modified it 
slightly:
<?xml version="1.0"?>
<batchup>
<x>0</x>
<x>1</x>
<x>2</x>
<x>3</x>
<x>4</x>
<x>5</x>
<x>6</x>
<x>7</x>
<x>8</x>
<x>9</x>
<x>0</x>
<x>1</x>
<x>2</x>

... and so on, for 1000 <x> elements.

Then I wrote a small stylesheet based on the FAQ method:

<xsl:variable name="groupsize" select="3"/>
<xsl:template match="/">
<xsl:for-each select="batchup/x[position() mod $groupsize = 1]">
 <xsl:text>&#xA;</xsl:text>
 <w>
    <xsl:copy-of select=".|following-sibling::x[position() &lt; $groupsize]"/>
 </w>
</xsl:for-each>
</xsl:template>

and another based on a recursive call-template:

<xsl:variable name="groupsize" select="3"/>
<xsl:template match="/">
 <xsl:call-template name="batchup">
    <xsl:with-param name="nodes" select="/batchup/x"/>
 </xsl:call-template>
</xsl:template>
<xsl:template name="batchup">
 <xsl:param name="nodes"/>
 <xsl:if test="$nodes">
 <xsl:text>&#xA;</xsl:text>
 <w>
 <xsl:copy-of select="$nodes[position() &lt;= $groupsize]"/>
 </w>
 <xsl:call-template name="batchup">
    <xsl:with-param name="nodes" select="$nodes[position() &gt; $groupsize]"/>
 </xsl:call-template>
 </xsl:if>
</xsl:template>

Not surprisingly, the second transform took about 5 times longer to run (83.34 
seconds on w2k/saxon6.5.1/750mhz) than the first one (17.46 seconds) (and 
Windows complained about my virtual memory usage). Not to mention that the 
first transform is a smaller amount of code.

- Mitch

Edward L. Knoll wrote:

I am creating a XSL stylesheet which effectively copies an input
XML stream to the output and introduces a level of XML elements for a
selected set of elements.   The problem I have run into is that there
does seem to be way to output the open tag of an element separately from
the closing tag.  I've come up with something which works using
to output the open and close tags; in short, I have to hide
the fact I'm outputting elements.  I am generating well-formed XML,
however, I can't seem to come up with a method which allows the elements
to be recognized as such while keeping the XSL well-formed.

I've included some representative XML at the end of this file.  Note
that there are subelements under the  elements in the example.
Additionally,  are subelements under another element.  I'm
effectively introducing a new level of element in the middle of an
existing XML element hierarchy.

Is there other recommended methods for doing this?  I'm interested in
general approaches to this type of problem (as opposed to a specific
solution to my specific problem).  Two specific aspects of the problem
I will note are: (a) the new grouping is based on a specified/constant
number of elements (e.g. every N  elements are being packaged under a
new element) and (b) I am potentially processing a great number of
elements (e.g. I need an effective solution).

Thanks,
Ed Knoll

p.s. I'm only subscribed to the digest, so if you could reply to me as
well as to the mailing list I'd appreciate it.

INPUT:
...
...
...
...
...
...
...
...
...

OUTPUT:

...
...
...


...
...
...


...
...
...


--
Edward L. Knoll   Phone (work)     : (719)484-2717
                 e-mail (work)    : f49660c(_at_)cosd(_dot_)fedex(_dot_)com
                 e-mail (business): eknoll(_at_)sf-inc(_dot_)com
                 e-mail (personal): edward(_at_)elknoll(_dot_)com









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





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