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 January 21st, 2009, 11:47 AM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Red face How to parse this list of users using XSLT 1

Hi. I'm using XSLT 1.

I'm giving the following input:
<Addressees>BILLY, GROUPA (EXCLUDE BOB, JANE), JANE DOE, SMITH FAMILY (EXCLUDE TIMMY), HEIDI,</Addressees>

I need to parse that input into these fields:
<User>BILLY</User>
<User Exclude='(EXCLUDE BOB, JANE)'>GROUPA</User>
<User>JANE DOE</User>
<User Exclude='(EXCLUDE TIMMY)'>SMITH FAMILY</User>
<User>HEIDI</User>

My XSLT code so far:
<xsl:template name='parse'>
<xsl:param name='str'/>
<xsl:variable name='user' select='substring-before($str, ',')/>
<User>
<xsl:value-of select="$user"/>
</User>
<!-- Recursively call to process the remaining users -->
<xsl:call-template name='parse'>
<xsl:with-param name='str' select='normalize-space(substring-after($str, ','))/>
</xsl:call-template>
</xsl:template>

My output so far (which is wrong):
<User>BILLY</User>
<User>GROUPA (EXCLUDE BOB</User>
<User>JANE)</User>
<User>JANE DOE</User>
<User>SMITH FAMILY (EXCLUDE TIMMY)</User>
<User>HEIDI</User>

Please help. Appreciate any help.
 
Old January 21st, 2009, 11:58 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Do you really need to do that with XSLT 1? That problem asks for more powerful string processing than XSLT 1.0 provides, at least without using extension functions.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old January 21st, 2009, 12:00 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This one looks pretty tough - it's tricky enough in XSLT 2.0 where you have much more powerful string handling.

It might be worth looking at the parsing framework of FXSL, though there's a steep learning curve involved.

Do you *really* have to do it in 1.0?
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old January 21st, 2009, 12:09 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes, it has to done in XSLT 1.
 
Old January 21st, 2009, 12:43 PM
Authorized User
 
Join Date: Oct 2006
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Wink

I recently instructed that I could produce this output as alternative:

<User>BILLY</User>
<User>GROUPA</User>
<Exclude>(EXCLUDE BOB, JANE)</Exclude>
<User>JANE DOE</User>
<User>SMITH FAMILY</User>
<Exclude>(EXCLUDE TIMMY)</Exclude>
<User>HEIDI</User>

Any help is appreciated.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Parse XML string parameter from XSLT maulik33 XSLT 6 December 5th, 2007 11:51 AM
Creating a list of users DennyLoi Javascript How-To 0 November 9th, 2007 04:32 AM
PHP Parse error: parse error, unexpected T_STRING geminient PHP How-To 4 August 18th, 2007 02:27 AM
Can I use XSLT to "unflatten" a list? dmorin XSLT 1 March 28th, 2007 03:04 PM





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