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

Re: Does <xsl:copy> use a lot of memory? Is there an

Subject: Re: Does <xsl:copy> use a lot of memory? Is there an alternative that is more efficient?
From: Graydon <graydon@xxxxxxxxx>
Date: Mon, 3 Sep 2012 11:24:01 -0400
Re:  Does <xsl:copy> use a lot of memory?  Is there an
On Mon, Sep 03, 2012 at 03:12:40PM +0000, Costello, Roger L. scripsit:
> >> In other words, if I don't immediately output the results of
> >> xsl:copy, then memory consumption grows and grows. Yes?
> >
> >Potentially yes.
> 
> Okay, then I am in a pickle and I see no way out.
> 
> Recall the problem that I am tackling: I have an element with an idref
> attribute. I want to fetch the referenced element and inline it.
> Here's the template to do that:
> 
>     <xsl:key name="ids" match="*[@id]" use="@id"/>
> 
>     <xsl:template match="*[@idref]">
>         
>         <xsl:variable name="refed-element" select="key('ids',
>         @idref)"/>
>         
>         <xsl:copy>  <xsl:copy-of select="@* except @idref" />
>         <xsl:sequence select="$refed-element" /> </xsl:copy>
>         
>     </xsl:template>

But why are you creating a variable at all?

> However, the element that I just inlined may have a reference. So I
> store the results into a variable and then repeat the process on the
> content of the variable. But that may also result in inlining an
> element with a reference, so I store the results into another variable
> and process it. I keep repeating this process until there are no more
> references. (The references may be recursive so it is a bit more
> involved than this, but you get the idea.)

Replace the variable reference in the sequence select with the contents
of the select in the variable, and it should just work, no?  Presuming
you're getting the element you just inlined from the same source
document, anyway.

The processor should handle document order for you, and the template
will match everything with an @idref.  You don't need to force that with
some sort of explicit recursion.

> In the process I described above, I am creating a bunch of variables.
> But with each new variable that I create, the previous variables are
> no longer used. It seems like the previous variables should be garbage
> collected. Is there a way to signal to an XSLT processor, "Hey, I am
> done with this variable, please garbage collect it"?

Generally speaking, don't create variables unless you can't avoid it; I
think you can't avoid it if you need to multiply reference something in
many templates, if you have to pipeline the processing, or if you're
forced to do a switch between serialized and node-based processing.

So far as I can tell from your example, you don't need variables at all.

If you _are_ getting the inlined content from another document than your
primary source document, figure out how deep it can go, and run the one
pass version -- NOT the forced recursion version -- that many times.
C(n) is better than n^2 unless C is larger than n.  (this is where you
do the chained pipeline thing with variables.)

-- Graydon

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.