p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 30th, 2009, 09:04 AM
Friend of Wrox
Points: 949, Level: 11
Points: 949, Level: 11 Points: 949, Level: 11 Points: 949, Level: 11
Activity: 23%
Activity: 23% Activity: 23% Activity: 23%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 Posts
Default Regex in xsl:analyze-string

Hi All,
I need your help in matching a string, which looks like
<TYPE>,,<TYPE2> in the input xml. The separator here is comma. There may or may not be values in between some of the commas, i.e., the input string may be like no text,,<TYPE2> or <TYPE>,,no text. I need to match the no text area also.

INPUT:
$blockValue = "no text,no text,<TYPE2>,no text"

Code:
<KEYWDBLOCK BLOCK="3">
<VALUE>
<xsl:value-of select="$blockValue"/></VALUE>
<xsl:analyze-string select="$blockValue" regex="([A-Z0-9\-\s]+)">
<xsl:matching-substring>
 
<KEYWD BLOCK="3">
<xsl:value-of select="."/>
</KEYWD>
 
</xsl:matching-substring>
</xsl:analyze-string>
</KEYWDBLOCK>
PRESENT OUTPUT:
Code:
<KEYWDBLOCK BLOCK="3">
<VALUE>,,&lt;TYPE2&gt;,</VALUE>
<KEYWD BLOCK="3">TYPE2</KEYWD>
</KEYWDBLOCK>


REQD. OUTPUT:
Code:
<KEYWDBLOCK BLOCK="3">
<VALUE>,,&lt;TYPE2&gt;,</VALUE>
<KEYWD BLOCK="3"></KEYWD>
<KEYWD BLOCK="3"></KEYWD>
<KEYWD BLOCK="3">TYPE2</KEYWD>
<KEYWD BLOCK="3"></KEYWD>
</KEYWDBLOCK>
Any help is appreciated.

Thanks in advance
__________________
Rummy

Last edited by mrame : June 30th, 2009 at 09:07 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old June 30th, 2009, 09:31 AM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

I think you're better off here using tokenize():

Code:
<xsl:for-each select="tokenize($blockValue, ',')">
  <KEYWD BLOCK="3">
     <xsl:value-of select="."/>
  </KEYWD>
</xsl:for-each>
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old July 1st, 2009, 02:06 AM
Friend of Wrox
Points: 949, Level: 11
Points: 949, Level: 11 Points: 949, Level: 11 Points: 949, Level: 11
Activity: 23%
Activity: 23% Activity: 23% Activity: 23%
 
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 Posts
Default

Many thanks Michael. It works fine.
__________________
Rummy
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:analyze-string - units of measure bonekrusher XSLT 2 April 16th, 2009 12:12 PM
Analyze-String and A Multiple-Match Example mphare XSLT 2 January 27th, 2009 05:21 PM
RegEx to match a string only if it does'nt have a particular string within it arshsidhu BOOK: Beginning Regular Expressions 1 January 27th, 2009 05:17 PM
analyze-string and variables pcase XSLT 1 June 8th, 2007 05:22 PM
match string in more than one line using Regex suman9730 General .NET 0 October 24th, 2006 03:27 AM



All times are GMT -4. The time now is 09:32 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc