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

November 21st, 2009, 11:53 PM
|
|
Registered User
|
|
Join Date: May 2009
Posts: 6
Thanks: 2
Thanked 0 Times in 0 Posts
|
|
The regular expression in replace() must not be one that matches a zero-length string
Stumped by the following error message:
"The regular expression in replace() must not be one that matches a zero-length string. 68:0"
What is bizarre to me is I am doing the same thing on line 16 which works fine (but is inside an analyze-string). I suspect the error is a misdirection given it points 2 lines below the actual statement.
Insights greatly appreciated,
Sample source (a log file)
Code:
10/1/2009 11:07:53 AM,10/1/2009 12:00:00 AM,"1111","pos3","DROOM","No sale Btn Pressed"
10/1/2009 11:07:54 AM,10/1/2009 12:00:00 AM,"1111","pos3","NO_SALE","1111 AM B drawer: NONE"
10/1/2009 11:13:50 AM,10/1/2009 12:00:00 AM,"1111","pos3","DROOM","No sale Btn Pressed"
10/1/2009 11:13:50 AM,10/1/2009 12:00:00 AM,"1111","pos3","NO_SALE","1111 AM B drawer: NONE"
10/1/2009 11:15:43 AM,10/1/2009 12:00:00 AM,"1111","pos3","NEW_ORDER","New order opened on table number NT01"
10/1/2009 11:15:45 AM,10/1/2009 12:00:00 AM,"1111","pos3","MENUOPTION","NON-ALCOHOL menu pressed (menu link: NON ALCOHOL). orderid: 428882"
10/1/2009 11:15:47 AM,10/1/2009 12:00:00 AM,"1111","pos3","LINE_ADDED","OrdID:428882 added Diet Coke $:1.65 Qty:1 st:1"
10/1/2009 11:15:48 AM,10/1/2009 12:00:00 AM,"1111","pos3","MENUOPTION","Menu Btn: Keyboard (link: KEYBOARD) pressed. orderid: 428882"
10/1/2009 11:15:52 AM,10/1/2009 12:00:00 AM,"1111","pos3","LINE_ADDED","OrdID:428882 added COCINA $:0 Qty:1 st:1"
10/1/2009 11:15:53 AM,10/1/2009 12:00:00 AM,"1111","pos3","MENUOPTION","Send btn pressed. (orderID: 428882)"
10/1/2009 11:15:53 AM,10/1/2009 12:00:00 AM,"1111","pos3","LINE_ADDED_DB","428882 sent: Diet Coke $:1.65 Qty:1"
Actual Code
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:param name="input-uri" as="xs:string"/>
<xsl:output indent="yes"/>
<xsl:template match="/" name="main">
<xsl:variable name="in" select="unparsed-text($input-uri, 'iso-8859-1')"/>
<xsl:analyze-string select="$in" regex="^([^,]+),([^,]+),"([0-9]{{4}}|[A-Z][0-9])","([a-zA-Z]{{3}}[0-9]|SERVER|EVS_SRV)","([0-9_a-zA-Z]+)","([^"]+)"" flags="m">
<xsl:matching-substring>
<xsl:variable name="entryTime" select="regex-group(1)"/>
<xsl:variable name="employeeID" select="regex-group(3)"/>
<xsl:variable name="stationID" select="upper-case(regex-group(4))"/>
<xsl:variable name="action" select="regex-group(5)"/>
<xsl:variable name="originalDescription" select="replace( regex-group(6), concat($employeeID," "), "")"/>
<xsl:variable name="orderID">
<xsl:choose>
<!-- Match Example: "OrdID: 428881 seats: 1,2,3 closed" -->
<xsl:when test="matches($originalDescription, 'OrdID:\s?[0-9]{6}' )">
<xsl:analyze-string select="$originalDescription" regex="(OrdID:\s?)([0-9]{{6}} )(.+$)">
<xsl:matching-substring>
<xsl:sequence select="regex-group(2)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<ERROR/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:when>
<!-- Match Example: "Close Check pressed. orderid: 428881" -->
<xsl:when test="matches($originalDescription, 'orderid:\s[0-9]{6}')">
<xsl:analyze-string select="$originalDescription" regex="(orderid:\s)([0-9]{{6}})">
<xsl:matching-substring>
<xsl:sequence select="regex-group(2)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<ERROR/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:when>
<!-- Match Example: 428882 reentered -->
<xsl:when test="matches($originalDescription, '[0-9]{6} reentered')">
<xsl:analyze-string select="$originalDescription" regex="^([0-9]{{6}})(\sreentered)$">
<xsl:matching-substring>
<xsl:sequence select="regex-group(2)"/>
</xsl:matching-substring>
<xsl:non-matching-substring>
<ERROR/>
</xsl:non-matching-substring>
</xsl:analyze-string>
</xsl:when>
<xsl:otherwise>
<xsl:text>##</xsl:text>
</xsl:otherwise>
<!-- 428887 sent: BLACK LABEL $:0.99 Qty:1 -->
<!-- New order opened on table number P21 -->
<!-- has SaleID 1063039-1 for $ 11.49 Cash ttl: $11.49 -->
</xsl:choose>
</xsl:variable>
<xsl:variable name="newDescription" select="replace( $originalDescription, $orderID, "")"/>
<xsl:element name="entry" > <xsl:value-of select="$entryTime, $employeeID, $stationID, $action, $orderID, $newDescription"/></xsl:element>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:template>
</xsl:stylesheet>
|
|

November 22nd, 2009, 06:18 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Your regular expression is the value of variable $orderID, and there's no way I can tell from reading your code what the value of this variable is. There are at least two paths on which the variable would have the value <ERROR/>, which would certainly trigger this message.
Add some diagnostics to determine the value of $orderID before the failure occurs.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
|
|
The Following User Says Thank You to mhkay For This Useful Post:
|
|
|
 |