Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 6th, 2006, 12:38 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default String maniuplation and concatentation

Hi,

I'm relatively new to XSLT and have the following problem...

My XML file has multiple nodes such as ...

...
<NAME>homer</NAME>
<NAME>marge</NAME>
<NAME>bart</NAME>
<NAME>lisa</NAME>
<NAME>maggie</NAME>
<TOWN>springfield</TOWN>
<STATE>unknown</STATE>
...

I'd like to concatentate the NAME tags and TOWN tag into one big string, equaling "homer marge bart lisa maggie springfield" and put that string into a new node in the xslt output. The question is...can this be done and HOW? I've found the concat() method, but can't seem to get the whole idea of a "variable to hold the string in process" to work.

Please help?!?!




 
Old July 6th, 2006, 12:46 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0, when your context node is the parent of the nodes you have shown, <xsl:value-of select="*"/> does exactly what you want.

In 1.0, use

<out>
  <xsl:for-each select="*">
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">
      <xsl:text> </xsl:text>
    </xsl:if>
  </xsl:for-each>
</out>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 6th, 2006, 02:03 PM
Registered User
 
Join Date: Jul 2006
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Awesome! Thank you for the quick reply.






Similar Threads
Thread Thread Starter Forum Replies Last Post
how to find a string in another string in vb6 satish_k VB How-To 3 March 30th, 2007 12:17 PM
Casting String array to string Samatha ASP.NET 1.0 and 1.1 Professional 1 December 5th, 2006 07:46 AM
syntax to find a string in a string cole SQL Server 2000 2 October 10th, 2005 06:06 PM
how to replace a string with another string/number crmpicco Javascript How-To 4 March 14th, 2005 12:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.