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 June 18th, 2010, 03:00 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default Strings to Elements

Maybe it's Friday and I'm not thinking clearly, but I'm struggling with a little problem. I have a string of strings separated by a delimiter. I would like to take the set of strings and convert each into an element node in a variable tree. There could be any number of strings in the set from 1 to n. The resulting tree would that many element nodes as well.

The input string comes from a parameter as the following:
Code:
<xsl:param name="StringSet" select="'First,Second,Third'"/>
The desired output looks something like this:
Code:
<xsl:variable name="stringTree" >
     <Strings>
         <String>First</String>
         <String>Second</String>
         <String>Third</String>
     </Strings>
</xsl:variable>
Any suggestions as to parse the input string to create this kind of tree? On a good day, I feel like I should be able to do this in my sleep :) Using Saxon 8.9 XSLT 2.0.

Thank you.
 
Old June 18th, 2010, 03:24 PM
Authorized User
 
Join Date: Apr 2008
Posts: 70
Thanks: 17
Thanked 1 Time in 1 Post
Send a message via Yahoo to iceandrews
Default

I'm not smart :) I figured it out. Thank you anyway.

Code:
<xsl:variable name="CodeList">
       <xsl:element name="Codes">
           <xsl:for-each select="tokenize($StringSet,',')">
               <xsl:element name="Code">
                   <xsl:value-of select="." />
               </xsl:element>
           </xsl:for-each>
       </xsl:element>
</xsl:variable>
This thread can be closed.
 
Old June 19th, 2010, 07:15 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Note that xsl: element is only necessary if you need to compute the element name or namespace, otherwise you can simply use a literal result element e.g.
Code:
<xsl:variable name="CodeList">
   <Codes>
       <xsl:for-each select="tokenize($StringSet, ',')">
           <Code>
              <xsl:value-of select="."/>
           </Code>
       </xsl:for-each>
    </Codes>
</xsl:variable>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chap 16 pg 574: Elements not supported Elements not known tomche BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 1 August 6th, 2009 02:48 PM
strings RoniR VB.NET 2002/2003 Basics 1 May 4th, 2007 02:55 PM
strings bschleusner C# 2005 3 February 27th, 2007 11:46 PM
strings... slowhand BOOK: ASP.NET Website Programming Problem-Design-Solution 1 January 5th, 2004 06:27 AM
strings slowhand SQL Server 2000 1 January 5th, 2004 12:20 AM





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