Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 software programmers and website developers 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 developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 7th, 2018, 02:50 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2018
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Exclamation Call external .class on Saxon 9HE Processor XSLT

Hi Guys,

I really need some help. I have a requirement to make Luhn Algorithm in one tag of the input XML.

I really could not find anything clear on pure XSLT code, but I already developed a java code and I just need to call it on XSLT.

I'm using the processor SAXON 9HE because also from input XML I need slipt into many output XML's.

As I mentioned before this tag on XML that I need use LUHN Algoritm input xml (This is just sample, the input XML and Java it's big to post here):

<?xml version="1.0" encoding="UTF-8"?>
<tag>urn:epc:id:sgtin:0614141.100013.00000000000 1</tag>

I have the java code read:

public class Luhn {
public static String LuhnAlgorithm(String card) {
.....
}

The code is runing perfect but now I need call the function LuhnAlgorithm inside XSLT to make the transformation:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="java:sumCheck.Luhn">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xmlLuhn>
<xsl:variable name="Luhn13Digits"
select="translate(concat('0',substring(.,19,13 )),'.','')"/>
<xmlJava>
<xsl:value-of select="java:LuhnAlgorithm($Luhn13Digits)"/>
</xmlJava>
</xmlLuhn>
</xsl:template>


Any Help I really appreciate. Thanks for your attention.

Kind Regards,

Flamengo
Reply With Quote
  #2 (permalink)  
Old June 7th, 2018, 03:26 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

Information on writing Java extension functions for calling from Saxon XSLT code can be found here:

http://www.saxonica.com/documentatio...!extensibility

The mechanism of "reflexive extension functions" which allows you to call directly into your Java code is not available in Saxon-HE. But you can wrap it up as an "integrated extension function".

But really, the Luhn algorithm can be implemented as an XSLT function just as easily as in Java.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
  #3 (permalink)  
Old June 7th, 2018, 04:10 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2018
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

mhkay

Thanks for fast replay.

I will check this about java, for you it's easier can you provide a real code ? Not this codes from Google about UPC etc because no works for me any.

I'm really trying code manually this math formula but start be hard.

Last edited by Flamengo; June 7th, 2018 at 04:29 AM.
Reply With Quote
  #4 (permalink)  
Old June 7th, 2018, 04:34 AM
mhkay's Avatar
Wrox Author
Points: 18,410, Level: 59
Points: 18,410, Level: 59 Points: 18,410, Level: 59 Points: 18,410, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,949
Thanks: 0
Thanked 289 Times in 284 Posts
Default

Sorry, this isn't a free code-writing service.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
Flamengo (June 7th, 2018)
  #5 (permalink)  
Old June 7th, 2018, 05:13 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2018
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

No Comments.

Last edited by Flamengo; June 7th, 2018 at 05:16 AM.
Reply With Quote
  #6 (permalink)  
Old June 7th, 2018, 08:44 AM
Registered User
Points: 15, Level: 1
Points: 15, Level: 1 Points: 15, Level: 1 Points: 15, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2018
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Solved via xslt:

<xsl:variable name="Luhn13Digits" select="translate(concat('0',substring(.,19,13 )),'.','')"/>
<xsl:variable name="restDigits" select="translate(concat('0',substring(.,32,13 )),'.','')"/>
<xsl:variable name="PairNumbers"
select="(((substring($Luhn13Digits, 2, 1)) + (substring($Luhn13Digits,4,1)) +
(substring($Luhn13Digits, 6, 1)) + (substring($Luhn13Digits, 8,1)) +
(substring($Luhn13Digits, 10, 1)) + (substring($Luhn13Digits, 12,1))))"/>
<xsl:variable name="Ludhpos13">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 13, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 13, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 13, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos11">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 11, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 11, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 11, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos9">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 9, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 9, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 9, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos7">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 7, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 7, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 7, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos5">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 5, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 5, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 5, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos3">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 3, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 3, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 3, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="Ludhpos1">
<xsl:choose>
<xsl:when test="substring($Luhn13Digits, 1, 1)*2 &gt; 9">
<xsl:value-of select="substring($Luhn13Digits, 1, 1)*2-9"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="substring($Luhn13Digits, 1, 1)*2"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="OddNumbers" select="$Ludhpos1+$Ludhpos3+$Ludhpos5+$Ludhpos7+$L udhpos9+$Ludhpos11+$Ludhpos13"/>
<xsl:variable name="LuhnMod10" select="$PairNumbers+$OddNumbers"/>

The rest..

Regards,
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Installing Saxon XSLT Processor booboop BOOK: Beginning XML 3rd Edition 2 April 7th, 2011 12:10 PM
Saxon 9HE and xquery for loops apollo13 XSLT 7 April 6th, 2010 07:02 AM
Which XSLT processor? li72 XSLT 1 August 16th, 2007 11:18 AM
what is this error generated by saxon processor? muki XSLT 8 February 12th, 2007 02:57 PM
Regarding the XSLT Processor sunrain XSLT 5 December 3rd, 2006 02:01 AM



All times are GMT -4. The time now is 06:18 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.