|
|
 |
| 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.
|
 |

June 30th, 2009, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 Posts
|
|
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>,,<TYPE2>,</VALUE>
<KEYWD BLOCK="3">TYPE2</KEYWD>
</KEYWDBLOCK>
REQD. OUTPUT:
Code:
<KEYWDBLOCK BLOCK="3">
<VALUE>,,<TYPE2>,</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.
|

June 30th, 2009, 09:31 AM
|
 |
Wrox Author
Points: 12,642, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,900
Thanks: 0
Thanked 80 Times in 78 Posts
|
|
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
|

July 1st, 2009, 02:06 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 205
Thanks: 9
Thanked 22 Times in 22 Posts
|
|
Many thanks Michael. It works fine.
__________________
Rummy
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |