[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

XPath MOD 10 calculation

Subject: XPath MOD 10 calculation
From: "Jesper Tverskov" <jesper@xxxxxxxxxxx>
Date: Thu, 24 May 2007 13:05:12 +0200
 XPath MOD 10 calculation
Hi list

I have made a MOD 10 calculation with XPath to check if a UPC barcode
number is legal. I am just wondering if the code could be made more
elegant with some of the new stuff in XPath 2.0.

Since I am going to use the test in Schematron, I can use variables
but not templates or other xsl elements than shown below.

The context value is some UPC code like 639382000393.

<xsl:variable name="x" select="((xs:integer(substring(., 1, 1)) +
xs:integer(substring(., 3, 1)) + xs:integer(substring(., 5, 1)) +
xs:integer(substring(., 7, 1)) + xs:integer(substring(., 9, 1)) +
xs:integer(substring(., 11, 1))) * 3 + (xs:integer(substring(., 2, 1))
+ xs:integer(substring(., 4, 1)) + xs:integer(substring(., 6, 1)) +
xs:integer(substring(., 8, 1)) + xs:integer(substring(., 10, 1)))) mod
10"/>

<xsl:if test="(if ($x ne 0) then (10 - $x) else $x) ne
xs:integer(substring(., 12, 1))">
<!-- Not legal, do something -->
</xsl:if>

Cheers,

Jesper Tverskov
http://www.xmlplease.com/xslt

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.