|
|
 |
| 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 tens of thousands of computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other programmers’ questions, win occasional prizes given to our best members, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
|
|
 |

June 30th, 2009, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2008
Location: Pondicherry, India
Posts: 212
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: 13,389, Level: 50 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,025
Thanks: 0
Thanked 114 Times in 112 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: 212
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
|
|
|
|
 |