[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: String hashing code
I don't have a XSLT solution. With Saxon I use for a similar problem an
extension which returns md5 hashes for the serialized content. Find the
source code below. I call it from within XSLT with
<xsl:variable name="serialized_content"> <xsl:value-of select="saxon:serialize(current-group()[1],'')"/> </xsl:variable> <xsl:variable name="hash"> <xsl:value-of select="md5:md5($serialized_content)"/> </xsl:variable> --- file md5.java --- import java.util.*; import java.io.*; import java.security.*; /* Saxon extension for generating unique hash values. */ public class Md5 { public static String hex(byte[] array) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < array.length; ++i) { sb.append(Integer.toHexString((array[i] & 0xFF) | 0x100).toUpperCase().substring(1,3)); } return sb.toString(); } public static String md5 (String message) throws NoSuchAlgorithmException, UnsupportedEncodingException { MessageDigest md = MessageDigest.getInstance("MD5"); return hex (md.digest(message.getBytes("CP1252"))); } } Deborah Pickett schrieb: A challenge to the XSLT demigods...
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|