Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

gather and concatinate data

Status
Not open for further replies.

CassidyHunt

IS-IT--Management
Jan 7, 2004
688
US
Is there a way in XSL to do this:

Code:
dim str as string
dim i as integer

for i = 0 to 10
   str = str & i & ";"
next

What my situation is I am running through a loop of data that I need to gather into one variable and print in a hidden element on a webpage. Then I will take my javascript and analyze it in an array.

I guess what I am lacking is to be able to modify a variable and keep the existing data stored in it.

Thanks

Cassidy
 
Not sure... maybe this will do for you?
[tt]
<!-- [blue]or some template of some match so select for str make more definitive meaning[/blue] -->
<xsl:template match="/">
[blue]<xsl:variable name="str" select="'abcde'" />[/blue]
<xsl:variable name="str_sffx">
<xsl:call-template name="base">
<xsl:with-param name="n" select="10" />
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="concat($str,$str_sffx)" />
</xsl:template>

<xsl:template name="base">
<xsl:param name="s" />
<xsl:param name="n" />
<xsl:if test="$n &gt;= 0">
<xsl:call-template name="callee">
<xsl:with-param name="m" select="$n" />
</xsl:call-template>
<xsl:value-of select="concat($n,';')" />
</xsl:if>
</xsl:template>

<xsl:template name="callee">
<xsl:param name="m" />
<xsl:call-template name="base">
<xsl:with-param name="n" select="$m - 1" />
</xsl:call-template>
</xsl:template>
[/tt]
 
Cassidy,

As always, an example of the input (probably simplified, but still showing the basic input structure) and the desired output would probably get a better answer.

My guess is that you can accomplish what you want to do in an xsl:for-each construct, inside an xsl:attribute, but I need to see the actual problem first.

Tom Morrison
 
Tom is right, there's probably a more elegant solution if the problem is better defined. For your general question though, iteration can only be done through recursion as in tsuji's post or below (although you could use tokenise function in XPath 2 or extensions).
Code:
<xsl:template match="/">
  <xsl:call-template name="iterate">
    <xsl:with-param name="end" select="10"/>
  </xsl:call-template>
</xsl:template>

<xsl:template name="iterate">
  <xsl:param name="i"/>
  <xsl:param name="end"/>
  <xsl:value-of select="concat($i, ';')" />
  <xsl:if test="$i &lt; $end">
    <xsl:call-template name="iterate">
      <xsl:with-param name="i" select="$i + 1" />
      <xsl:with-param name="end" select="10"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

Jon

"I don't regret this, but I both rue and lament it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top