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

Tracking position in recursive functions?

Subject: Tracking position in recursive functions?
From: himanshu padmanabhi <himanshu.padmanabhi@xxxxxxxxx>
Date: Thu, 2 Apr 2009 12:25:56 +0530
 Tracking position in recursive functions?
Hi,

These is just the part of str::tokenize.

I just want to ask how to track "position" in recursive functions like
"str:_tokenize-delimiters"?

"position()" isn't solving the purpose.

"$args" value is "-p 10 -t 20 abcd.domain.com" which I want to
tokenize by space.

What my final goal is,
If called with position()=1 then print 2nd pos = 10
If called with position()=2 then print 4nd pos = 20
If called with position()=3 then print 5nd pos = abcd.domain.com
(There are 3 xml elements so str:tokenize can be called 3 times or I
call it 1 time and save 2,4,5 values in variables and can print it in
calling template.)

Currently it is printing all the tokens each time.
Tracking 'position' in recursive function also can give me answer like
2nd,4th,5th position token.

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:str="http://exslt.org/strings"
                extension-element-prefixes="str">

<xsl:template name="str:_tokenize-delimiters">
  <xsl:param name="args" />
  <xsl:param name="delimiters" />

  <xsl:variable name="delimiter" select="substring($delimiters, 1, 1)" />

  <xsl:choose>
        <xsl:when test="not($delimiter)" >
            <option><xsl:value-of select="$args" /></option>
        </xsl:when>

    <xsl:when test="contains($args, $delimiter)">
        <option><xsl:value-of select="substring-after($args,
$delimiter)" /></option>
        <xsl:if test="not(starts-with($args, $delimiter))">
            <xsl:call-template name="str:_tokenize-delimiters">
                <xsl:with-param name="args"
select="substring-before($args, $delimiter)" />
                <xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
            </xsl:call-template>
        </xsl:if>

        <xsl:call-template name="str:_tokenize-delimiters">
            <xsl:with-param name="args" select="substring-after($args,
$delimiter)" />
            <xsl:with-param name="delimiters" select="$delimiters" />
        </xsl:call-template>
    </xsl:when>

    <xsl:otherwise>
        <xsl:call-template name="str:_tokenize-delimiters">
            <xsl:with-param name="args" select="$args" />
            <xsl:with-param name="delimiters"
select="substring($delimiters, 2)" />
        </xsl:call-template>
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>
---------------------------------
Thanks and Regards,
Himanshu Padmanabhi

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.