[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Re: [xsl] RE : Re: [xsl] Complex recursion in XSLT 1.0
Subject: Re: [xsl] RE : Re: [xsl] Complex recursion in XSLT 1.0 From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Wed, 20 Feb 2008 22:54:22 +0530 |
Thanks for sharing the example. I further tested the program as following: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:x="http://xsl/stack" version="2.0"> <xsl:output method="text" /> <xsl:template match="/"> <!-- 1. --> <xsl:variable name="stack" select="()" /> <!-- 2. --> <xsl:variable name="stack" select="x:push($stack, 1)" /> <!-- 3. --> <xsl:value-of select="x:top($stack)" /> <!-- 4. --> <xsl:variable name="stack" select="x:push($stack, 2)" /> <!-- 5. --> <xsl:value-of select="x:top($stack)" /> <!-- 6. --> <xsl:value-of select="x:top(x:pop($stack))" /> </xsl:template> <xsl:function name="x:push" as="item()+"> <xsl:param name="stack" as="item()*"/> <xsl:param name="item" as="item()"/> <xsl:sequence select="$item, $stack"/> </xsl:function> <xsl:function name="x:pop" as="item()*"> <xsl:param name="stack" as="item()*"/> <xsl:sequence select="remove($stack, 1)"/> </xsl:function> <xsl:function name="x:top" as="item()?"> <xsl:param name="stack" as="item()*"/> <xsl:sequence select="$stack[1]"/> </xsl:function> </xsl:stylesheet> I get the output: 121 I am happy with this; but have following questions: 1) On this line <!-- 2. --> , I create a variable 'stack'. This is a new *variable* and not the old one (on line <!-- 1. -->; because we cannot modify variables in XSLT). This doesn't make me quite happy :) 2) On line <!-- 6. -->, I do x:top(x:pop($stack)). This modifies a transient stack, and doesn't modify the variable $stack. I would like the variable $stack to be modified. But that's not possible, we know :) I guess, these limitations will prohibit some stack specific programs to be built. Can we think of some strategies to overcome these limitations. On Wed, Feb 20, 2008 at 9:19 PM, Florent Georges <lists@xxxxxxxxxxxx> wrote: > <xsl:function name="x:push" as="item()+"> > <xsl:param name="stack" as="item()*"/> > <xsl:param name="item" as="item()"/> > <xsl:sequence select="$item, $stack"/> > </xsl:function> > > <xsl:function name="x:pop" as="item()*"> > <xsl:param name="stack" as="item()*"/> > <xsl:sequence select="remove($stack, 1)"/> > </xsl:function> > > <xsl:function name="x:top" as="item()?"> > <xsl:param name="stack" as="item()*"/> > <xsl:sequence select="$stack[1]"/> > </xsl:function> > > :-) > > That's just an idea, you might want to control more > precisely errors (what if one pops an empty stack?, etc.) -- Regards, Mukul Gandhi
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] RE : Re: [xsl] Complex recurs, Florent Georges | Thread | Re: [xsl] RE : Re: [xsl] Complex re, Florent Georges |
[xsl] RE : Re: [xsl] Complex recurs, Florent Georges | Date | Re: [xsl] RE : Re: [xsl] Complex re, Florent Georges |
Month |