You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@cocoon.apache.org by Jens Reufsteck <je...@hobsons.de> on 2007/11/06 14:17:30 UTC

limited number of loops with call-template?

Hi list!


I'm using a template, which once called from outside  starts calling itself
as long as a certain condition is true. But after a certain amount of calls
(1.100 times) it seems stopping to call itself. The processing stops in the
middle of the xml-document without throwing an exception and without
throwing the resulting xml-document.


This is the template:

<xsl:template name="baum">
	<xsl:param name="position"/>
	...	
	<xsl:if test="/website/ebene[position()=$position]/text() =
/website/ebene[position()=$position + 1]/text()">
		<xsl:call-template name="baum">
			<xsl:with-param name="position" select="$position +
1"/>
		</xsl:call-template>
	</xsl:if>
</xsl:template>
	

The result looks like this:
<website>
	<baum ebene="1">
		de
		<ebene ebene="2">
			education
				<file>diplom.html</file>
		</ebene>
		... [further 1099 entries]
		<ebene ebene="2"/>


Has anyone an idea what to do? Any help is appreciated!

Jens

-- 
Jens Reufsteck
Hobsons GmbH
Wildunger Straße 6
60487 Frankfurt am Main
Deutschland

Tel: +49 (69) 255 37-140
Fax: +49 (69) 255 37-2140

http://www.hobsons.de
http://www.hobsons.ch

Geschäftsführung:
Christopher Letcher, Judith Oppitz, Adam Webster
Amtsgericht Frankfurt HRB 58610


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: limited number of loops with call-template?

Posted by Tobia <to...@linux.it>.
Jens Reufsteck wrote:
> I'm using a template, which once called from outside starts calling
> itself as long as a certain condition is true. But after a certain
> amount of calls (1.100 times) it seems stopping to call itself.

I wouldn't write a template that calls itself recursively that many
times, unless I was sure that the implementation is tail-recursive and
that I am writing a tail-recursive template.

Said another way, try and traverse the document using matching (not
named) templates and apply-templates, along with modes if needed.

Based on your scarce snippet, you could try something like this:

  <xsl:template match="ebene">
    <xsl:if test="text() != preceding-sibling::ebene[1]/text()">
      <!-- we are looking at the first "ebene" of its kind:
           output all the "ebene" with that value inside a "baum" -->
      <baum ebene="{text()}">
        <xsl:apply-templates select="../ebene[text() = current()/text()]"
                             mode="output"/>
      </baum>
    </xsl:if>
  </xsl:template>

  <xsl:template match="ebene" mode="output">
    <ebene>
      ...
    </ebene>
  </xsl:template>

Of course, I don't have the slightest idea what baums and ebenes are, so
this is probably not what you need :-)


Tobia

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: limited number of loops with call-template?

Posted by Jens Reufsteck <je...@hobsons.de>.
Just to confirm, Muenchian Grouping solves the problem. Great. Many thanks,
Joerg!

Jens

-- 
Jens Reufsteck
Hobsons GmbH
Wildunger Straße 6
60487 Frankfurt am Main
Deutschland

Tel: +49 (69) 255 37-140
Fax: +49 (69) 255 37-2140

http://www.hobsons.de
http://www.hobsons.ch

Geschäftsführung:
Christopher Letcher, Judith Oppitz, Adam Webster
Amtsgericht Frankfurt HRB 58610 

>-----Original Message-----
>From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de] 
>Sent: Wednesday, November 07, 2007 5:06 AM
>To: users@cocoon.apache.org
>Subject: Re: limited number of loops with call-template?
>
>On 06.11.2007 8:17 Uhr, Jens Reufsteck wrote:
>
>> I'm using a template, which once called from outside  starts 
>calling itself
>> as long as a certain condition is true. But after a certain 
>amount of calls
>> (1.100 times) it seems stopping to call itself. The 
>processing stops in the
>> middle of the xml-document without throwing an exception and without
>> throwing the resulting xml-document.
>
>I guess at some point the stack is just too big, but maybe the 
>exception 
>gets swallowed. But what actually happens? It can not just stop and do 
>nothing. Is it like an exception would have been thrown but does not 
>show up anywhere?
>
>> This is the template:
>> 
>> <xsl:template name="baum">
>> 	<xsl:param name="position"/>
>> 	...	
>> 	<xsl:if test="/website/ebene[position()=$position]/text() =
>> /website/ebene[position()=$position + 1]/text()">
>> 		<xsl:call-template name="baum">
>> 			<xsl:with-param name="position" 
>select="$position +
>> 1"/>
>> 		</xsl:call-template>
>> 	</xsl:if>
>> </xsl:template>
>> 	
>> 
>> The result looks like this:
>> <website>
>> 	<baum ebene="1">
>> 		de
>> 		<ebene ebene="2">
>> 			education
>> 				<file>diplom.html</file>
>> 		</ebene>
>> 		... [further 1099 entries]
>> 		<ebene ebene="2"/>
>> 
>
>Translation: baum = tree, ebene = level.
>
>What you are doing looks very much like grouping. You should 
>have a look 
>into so-called Muenchian Grouping. Feel free to ask if you 
>want to know 
>more about it. I can help you with that if you give me some 
>details from 
>the input and the grouping rules.
>
>Joerg
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


RE: limited number of loops with call-template?

Posted by Jens Reufsteck <je...@hobsons.de>.
Hi Joerg,

many thanks for your answer and the hint to the Muenchian Grouping. I had
only little time to look into that and didn't get every detail so far. But
it's probably in fact what I'm looking for!

I'm actually trying to convert a list of urls into a tree-like structure.
What I have is:
<document>
  <page>de/dboffline.html</pag>
  <page>de/education/diplom.html</page>
  <page>de/education/firma.html</page>
  ... [ca. 4.000 more]
</document>

What I'd like to get is:
<website>
	<level level="1">
		de
		<file>dboffline.html</file>
		<level level="2">
			education
			<file>diplom.html</file>
		...
</website>

If there is any more concrete idea how to set up the grouping, this would be
great. 

Re my initial point: The result I was getting was the unfinished xml-tree as
in my first email. In the pipeline I had set outputBufferSize="0", which I
assume is the reason, why I got this piece of xml instead of an exception. I
haven't retried this, but will continue with the grouping idea as above.

Thanks again

Jens


-- 
Jens Reufsteck
Hobsons GmbH
Wildunger Straße 6
60487 Frankfurt am Main
Deutschland

Tel: +49 (69) 255 37-140
Fax: +49 (69) 255 37-2140

http://www.hobsons.de
http://www.hobsons.ch

Geschäftsführung:
Christopher Letcher, Judith Oppitz, Adam Webster
Amtsgericht Frankfurt HRB 58610 

>-----Original Message-----
>From: Joerg Heinicke [mailto:joerg.heinicke@gmx.de] 
>Sent: Wednesday, November 07, 2007 5:06 AM
>To: users@cocoon.apache.org
>Subject: Re: limited number of loops with call-template?
>
>On 06.11.2007 8:17 Uhr, Jens Reufsteck wrote:
>
>> I'm using a template, which once called from outside  starts 
>calling itself
>> as long as a certain condition is true. But after a certain 
>amount of calls
>> (1.100 times) it seems stopping to call itself. The 
>processing stops in the
>> middle of the xml-document without throwing an exception and without
>> throwing the resulting xml-document.
>
>I guess at some point the stack is just too big, but maybe the 
>exception 
>gets swallowed. But what actually happens? It can not just stop and do 
>nothing. Is it like an exception would have been thrown but does not 
>show up anywhere?
>
>> This is the template:
>> 
>> <xsl:template name="baum">
>> 	<xsl:param name="position"/>
>> 	...	
>> 	<xsl:if test="/website/ebene[position()=$position]/text() =
>> /website/ebene[position()=$position + 1]/text()">
>> 		<xsl:call-template name="baum">
>> 			<xsl:with-param name="position" 
>select="$position +
>> 1"/>
>> 		</xsl:call-template>
>> 	</xsl:if>
>> </xsl:template>
>> 	
>> 
>> The result looks like this:
>> <website>
>> 	<baum ebene="1">
>> 		de
>> 		<ebene ebene="2">
>> 			education
>> 				<file>diplom.html</file>
>> 		</ebene>
>> 		... [further 1099 entries]
>> 		<ebene ebene="2"/>
>> 
>
>Translation: baum = tree, ebene = level.
>
>What you are doing looks very much like grouping. You should 
>have a look 
>into so-called Muenchian Grouping. Feel free to ask if you 
>want to know 
>more about it. I can help you with that if you give me some 
>details from 
>the input and the grouping rules.
>
>Joerg
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
>For additional commands, e-mail: users-help@cocoon.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org


Re: limited number of loops with call-template?

Posted by Joerg Heinicke <jo...@gmx.de>.
On 06.11.2007 8:17 Uhr, Jens Reufsteck wrote:

> I'm using a template, which once called from outside  starts calling itself
> as long as a certain condition is true. But after a certain amount of calls
> (1.100 times) it seems stopping to call itself. The processing stops in the
> middle of the xml-document without throwing an exception and without
> throwing the resulting xml-document.

I guess at some point the stack is just too big, but maybe the exception 
gets swallowed. But what actually happens? It can not just stop and do 
nothing. Is it like an exception would have been thrown but does not 
show up anywhere?

> This is the template:
> 
> <xsl:template name="baum">
> 	<xsl:param name="position"/>
> 	...	
> 	<xsl:if test="/website/ebene[position()=$position]/text() =
> /website/ebene[position()=$position + 1]/text()">
> 		<xsl:call-template name="baum">
> 			<xsl:with-param name="position" select="$position +
> 1"/>
> 		</xsl:call-template>
> 	</xsl:if>
> </xsl:template>
> 	
> 
> The result looks like this:
> <website>
> 	<baum ebene="1">
> 		de
> 		<ebene ebene="2">
> 			education
> 				<file>diplom.html</file>
> 		</ebene>
> 		... [further 1099 entries]
> 		<ebene ebene="2"/>
> 

Translation: baum = tree, ebene = level.

What you are doing looks very much like grouping. You should have a look 
into so-called Muenchian Grouping. Feel free to ask if you want to know 
more about it. I can help you with that if you give me some details from 
the input and the grouping rules.

Joerg

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@cocoon.apache.org
For additional commands, e-mail: users-help@cocoon.apache.org