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 30th, 2009, 08:04 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 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 08:07 AM..
 
Old June 30th, 2009, 08:31 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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
 
Old July 1st, 2009, 01:06 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default

Many thanks Michael. It works fine.
__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:analyze-string - units of measure bonekrusher XSLT 2 April 16th, 2009 11:12 AM
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 04:22 PM
match string in more than one line using Regex suman9730 General .NET 0 October 24th, 2006 02:27 AM





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