• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Concating two strings in XSL

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have an array of textboxes in XSL file and I need to name them uniquely. My idea is to process them in a loop and append the loop variable to the control name. I tried with '+' and '&' but it's not working... Can some one suggest how I can concatenate???

------------------
 
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Krishna, are you doing all this in XSLT? If so, you may want to try a different approach. In XSLT variables are inmutable. Once you created a variable, you cannot update its value. What you want can be achieved using position() function: it enumerates nodes when you select them. To concatenate position()�s value with your control name you simply put them together. Assuming your control name has a value �ControlName� you code:
ControlName<xsl:value-of select="position()"/>
and concatenated value is outputted.
If your XML look like:
<?xml version="1.0"?>
<boxes>
<textbox>textbox1</textbox>
<textbox>textbox2</textbox>
<textbox>textbox3</textbox>
<textbox>textbox4</textbox>
</boxes>
you can use XSLT like this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<xsl:for-each select="boxes/textbox">
ControlName<xsl:value-of select="position()"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
the output is:
ControlName1 ControlName2 ControlName3 ControlName4
Is that what you need?
 
Krishna Mudda
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Mapraputa,
Thanks for your suggestion. But my requirement is slightly different. Let me be more clear.
Depending on the data I get from server in a XML string with XSL reference in it, I need to create additional rows in the table. So here I need to name the newly added controls so that I can use these names in my validations. So in XSL I need to append a value to control name to make it Unique.
Here concatinated string is to be attached to the name property.

Originally posted by Mapraputa Is:
Krishna, are you doing all this in XSLT? If so, you may want to try a different approach. In XSLT variables are inmutable. Once you created a variable, you cannot update its value. What you want can be achieved using position() function: it enumerates nodes when you select them. To concatenate position()�s value with your control name you simply put them together. Assuming your control name has a value �ControlName� you code:
ControlName<xsl:value-of select="position()"/>
and concatenated value is outputted.
If your XML look like:
<?xml version="1.0"?>
<boxes>
<textbox>textbox1</textbox>
<textbox>textbox2</textbox>
<textbox>textbox3</textbox>
<textbox>textbox4</textbox>
</boxes>
you can use XSLT like this:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html><body>
<xsl:for-each select="boxes/textbox">
ControlName<xsl:value-of select="position()"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
the output is:
ControlName1 ControlName2 ControlName3 ControlName4
Is that what you need?



------------------
 
Mapraputa Is
Leverager of our synergies
Posts: 10065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see now... You want to write something like
<text onclick="validate('textbox123')">
in your XSLT?
Then you define a template and call it recursively with a parameter, decremented each time. For example, if you need to generate 5 text elements, it will look like
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:call-template name="boxGenerator">
<xsl:with-param name="counter" select="5"/>
</xsl:call-template>
</body>
</html>
</xsl:template>
<xsl:template name="boxGenerator">
<xsl :param name="counter"/>
<xsl:if test="$counter != 0">
<xsl:call-template name="boxGenerator">
<xsl:with-param name="counter" select="$counter - 1"/>
</xsl:call-template>
<text onclick="validate('textbox{$counter}')">text</text><br/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
The output will be
<text onclick="validate('textbox1')">text</text>
<text onclick="validate('textbox2')">text</text>
...
<text onclick="validate('textbox5')">text</text>

[This message has been edited by Mapraputa Is (edited June 21, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!