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 May 22nd, 2007, 10:29 AM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regular Expressions XSLT 2.0

I am trying to isolate a regular expression group using the following XSLT:

<xsl:template name="extract_regex">
  <xsl:param name="regex">\Bulk Projects\Bulk ([\d]{3}) ([0-3][1-9](?i)(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|D ec)(?-i)(19|20)\d\d))</xsl:param>
  <xsl:param name="key_position">2</xsl:param>
  <xsl:param name="source_filename">\Project\Bulk 002 16Jan2006</xsl:param>
  <xsl:analyze-string select="$source_filename" regex="$regex">
    <xsl:matching-substring>
      <xsl:value-of select="regex-group($key_position)" />
    </xsl:matching-substring>
  </xsl:analyze-string>
</xsl:template>

I have explicitly defined the parameters to make my code snippet easier to follow. In this example, I am trying to extract the date (or the 2nd regex-group). Currently the code is not returning anything.

Any help is greatly appreciated.

 
Old May 22nd, 2007, 11:26 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

First of all, you need regex="{$regex}".

But also, you need to fix your regular expression, it's using many constructs that are not allowed in the XPath regular expression language, for example \B, (?i), (?-i).

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 22nd, 2007, 12:59 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have modified my template and am now using different sample data and regex:

<xsl:template name="extract_regex">
  <xsl:param name="match_value_object">\s*(.*)\s*,\s*([A-Z]{{2}})\s+(\d{{5}}(\-\d{{4}})?)\s*</xsl:param>
  <xsl:param name="key_position"/>
  <xsl:param name="input">New Haven, CT 06460</xsl:param>
  <xsl:analyze-string select="$input" regex="{$match_value_object}">
      <xsl:matching-substring>
          <xsl:value-of select="regex-group(2)" />
      </xsl:matching-substring>
  </xsl:analyze-string>
</xsl:template>

But I am receiving an error from Saxon:
com.sun.org.apache.xerces.internal.impl.io.Malform edByteSequenceException: Invalid byte 1
of 1-byte UTF-8 sequence

 
Old May 22nd, 2007, 02:43 PM
Authorized User
 
Join Date: May 2007
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Please disregard the previous post. And thank you for your help.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Do I need regular expressions..? ypomonh XSLT 2 May 20th, 2007 05:09 PM
Help with Regular Expressions WestRowOps Other Programming Languages 1 May 18th, 2007 05:34 AM
Regular expressions on C# hideway C# 2 November 27th, 2006 05:08 PM
Regular Expressions The_Iceman ASP.NET 2.0 Basics 0 September 29th, 2006 05:06 AM
I need some help in regular expressions! marwaesmat Perl 2 March 7th, 2006 05:22 PM





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