www.webdeveloper.com
Results 1 to 4 of 4

Thread: recursion in xslt

Hybrid View

  1. #1
    Join Date
    Oct 2003
    Posts
    2

    recursion in xslt

    Hi,
    I am a new user of XSLT. The XML file I am working is the expression 1+2*3 which I need to evaluate:

    <simpl:expression xmlns:simpl='urn:simpl'>
    <simpl: primitiveapplication>
    <simpl: operator>+</simpl: operator>
    <simpl:argument1>
    <simpl:intconstant>1</simpl:intconstant>
    </simpl:argument1>
    <simpl:argument2>
    <simpl: primitiveapplication>
    <simpl: operator>*</simpl: operator>
    <simpl: argument1>
    <simpl:intconstant>2</simpl:intconstant>
    </simpl:argument1>
    <simpl:argument2>
    <simpl:intconstant>3</simpl:intconstant>
    </simpl:argument2>
    </simpl: primitiveapplication>
    </simpl:argument2>
    </simpl: primitiveapplication>
    </simpl:expression>


    My current XSLT stylsheet can handle only expressions such as 1+2, 3*4, true|false etc where I have atmost 2 operands and looks like this:

    <xsl:template match="/">
    <xsl:variable name="op" select="/simpl: expression/simpl: primitiveapplication/simpl: operator">
    </xsl: variable>
    <xsl: variable name="arg1" select="/simpl: expression/simpl: primitiveapplication/simpl:argument1/simpl: intconstant">
    </xsl:variable>
    <xsl:variable name="arg2" select="/simpl:expression/simpl: primitiveapplication/simpl:argument2/simpl:intconstant">
    </xsl:variable>
    <xsl:variable name="boolarg1" select="/simpl:expression/simpl: primitiveapplication/simpl:argument1/simpl: boolconstant">
    </xsl:variable>
    <xsl:variable name="boolarg2" select="/simpl:expression/simpl: primitiveapplication/simpl:argument2/simpl:boolconstant">
    </xsl:variable>
    <xsl:choose>

    <xsl:when test='$op="+"'>
    <html><body><xsl:value-of select="$arg1 + $arg2"/></body></html>
    </xsl:when>
    ...and so on.

    Could someone tell me how to modify my current code so that I can cater to expressions such as 1+2*3 etc?
    I would appreciate any help. Thank you.
    Last edited by swatiw; 10-19-2003 at 07:17 AM.

  2. #2
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    37
    Hi,

    From what i understood, the reason you were able to make it work for only two arguments was cause u have hardcoded it 2 arg1 and arg2...instead i would recommend use <xsl:for-each select="argument1"> or something similar...form an expression using the concat() function of XSLT to form your string....

    HTH.

  3. #3
    Join Date
    Oct 2003
    Posts
    2
    Hi,
    Thanks for your reply. Yup- the problem was with the hard-coding. I modified it and it works fine now. Thanks!
    best,
    swati

  4. #4
    Join Date
    Sep 2003
    Location
    Australia
    Posts
    37
    Glad 2 be of Help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles