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 November 17th, 2011, 12:37 PM
Authorized User
 
Join Date: Feb 2008
Posts: 12
Thanks: 1
Thanked 0 Times in 0 Posts
Default Regular expression format in xslt

Hello All,

I need to implement Regular expression functionality for a list of data.

I need the Regex format like this (xxx-xxxxx)

here x= Alphanumeric

The list of data is like this

i/p:
1)aspn-et123
2)1aspnet-12
3)98asp-net.1.0

I need the o/p like this

o/p:
1)asp-net12
2)1as-pnet1
3)98a-spnet

Thanks


__________________
tq98
 
Old November 17th, 2011, 01:48 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Here is an example with XSLT 2.0, assuming the input is
Code:
<root>
  <item>aspn-et123</item>
  <item>1aspnet-12</item>
  <item>98asp-net.1.0</item>
</root>
then the stylesheet
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="2.0">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* , node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="item">
    <xsl:copy>
      <xsl:analyze-string select="replace(., '-', '')" regex="(\w{{3}})(\w{{5}})">
        <xsl:matching-substring>
          <xsl:value-of select="concat(regex-group(1), '-', regex-group(2))"/>
        </xsl:matching-substring>
      </xsl:analyze-string>
    </xsl:copy>
  </xsl:template>
  
</xsl:stylesheet>
outputs
Code:
<root>
  <item>asp-net12</item>
  <item>1as-pnet1</item>
  <item>98a-spnet</item>
</root>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
regular expression in xslt rajesh_css XSLT 2 September 22nd, 2008 02:14 AM
Regular Expression in C++ praveenholal C++ Programming 1 March 4th, 2007 01:18 AM
Regular Expression Help anshul PHP How-To 4 December 8th, 2004 05:19 AM
Regular Expression Help Greg Griffiths Javascript How-To 4 November 12th, 2004 05:33 AM
Regular Expression DARSIN General .NET 2 November 9th, 2004 08:30 AM





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