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 November 3rd, 2006, 01:33 PM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Further analysis

Hi forum!
I've got the next text:
<book>/data?author=Robert Law&amp;year=2006&amp;code=129&amp;md=H
</book>

I have to separe the string between <book> and </book> after '?' in the following elements:
<book> <author>Robert Law</author>
       <year>2006</year>
       <code>129</code>
       <md>H</md>
</book>

The & character separates each attribute. Is there any way of doing this with XSLT. It's important to say that the number of attributes changes in each book element. Some could include 'md' but other dont, instead could have pt = 3. The idea is to take the name when parsing the string as element name and after '=' correspond to its value.

Thanks in advanced!

 
Old November 3rd, 2006, 01:58 PM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Very easy using version 2.0, you can use tokenize function or analyze-string element. With version 1.0 you probably need a recursive template that uses substring-before to read the part upto the ampersand. Create your element and then pass the remaining string to the template etc. until all the string is processed.

--

Joe (Microsoft MVP - XML)
 
Old November 3rd, 2006, 02:55 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 you can use regular expressions to perform such string manipulation, using the xsl:analyze string instruction.

In 1.0 you've only got the functions such as substring-before, contains(), and substring-after(). If the text contains a pattern that repeats a variable number of times, you will need to analyze it using a recursive template. For an example, see the str:tokenize template found at www.exslt.org (you might even be able to use this directly)

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old November 6th, 2006, 07:13 PM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply Joe and Michael too.








Similar Threads
Thread Thread Starter Forum Replies Last Post
Do you use Analysis Services? valiko_work SQL Server 2005 0 August 10th, 2007 05:41 AM
Analysis Services Backup jemacc SQL Server 2000 0 November 15th, 2006 12:36 PM
Crystal Analysis SaralaManoharan Classic ASP Professional 0 December 21st, 2005 08:36 AM
Analysis Manager ColdFusionRO SQL Server 2000 1 July 25th, 2003 05:39 PM
TOP N Analysis rj SQL Server 2000 1 July 13th, 2003 10:21 PM





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