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

Re: RE : Re: Complex recursion in XSLT 1.0

Subject: Re: RE : Re: Complex recursion in XSLT 1.0
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 20 Feb 2008 22:54:22 +0530
Re:  RE : Re:  Complex recursion in XSLT 1.0
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

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-2007 All Rights Reserved.