Note that there are some explanatory texts on larger screens.

plurals
  1. POXSLT: Obtaining or matching hashes for base64 encoded data
    primarykey
    data
    text
    <p>I need to find a way to find a way to find the hash for the base64 encoded data in the XML node <strong>//note/resource/data</strong>, or somehow otherwise match it to the hash value in the node <strong>//note/content/en-note//en-media@hash</strong></p> <p><em>See below for the full XML file</em> </p> <p>Please suggest a way to {obtain|match} <strong>using XSLT</strong></p> <pre><code>4aaafc3e14314027bb1d89cf7d59a06c </code></pre> <p>{from|with} </p> <pre><code>R0lGODlhEAAQAPMAMcDAwP/crv/erbigfVdLOyslHQAAAAECAwECAwECAwECAwECAwECAwECAwEC AwECAyH/C01TT0ZGSUNFOS4wGAAAAAxtc09QTVNPRkZJQ0U5LjAHgfNAGQAh/wtNU09GRklDRTku MBUAAAAJcEhZcwAACxMAAAsTAQCanBgAIf8LTVNPRkZJQ0U5LjATAAAAB3RJTUUH1AkWBTYSQXe8 fQAh+QQBAAAAACwAAAAAEAAQAAADSQhgpv7OlDGYstCIMqsZAXYJJEdRQRWRrHk2I9t28CLfX63d ZEXovJ7htwr6dIQB7/hgJGXMzFApOBYgl6n1il0Mv5xuhBEGJAAAOw== </code></pre> <p>This sample XML file has obviously been trimmed for brevity/simplicity. The actual may contain &gt; 1 image per note, therefore the need to obtain/match hashes.</p> <p>The XML file:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE en-export SYSTEM "http://xml.evernote.com/pub/evernote-export.dtd"&gt; &lt;en-export export-date="20091029T063411Z" application="Evernote/Windows" version="3.0"&gt; &lt;note&gt; &lt;title&gt;A title here&lt;/title&gt; &lt;content&gt;&lt;![CDATA[ &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml.dtd"&gt; &lt;en-note bgcolor="#FFFFFF"&gt; &lt;p&gt;Some text here (followed by the picture) &lt;p&gt;&lt;en-media hash="4aaafc3e14314027bb1d89cf7d59a06c" type="image/gif" border="0" width="16" height="16" alt="A picture"/&gt;&lt;/p&gt; &lt;p&gt;Some more text here (preceded by the picture) &lt;/en-note&gt; ]]&gt;&lt;/content&gt; &lt;created&gt;20090925T063154Z&lt;/created&gt; &lt;note-attributes&gt; &lt;author/&gt; &lt;/note-attributes&gt; &lt;resource&gt; &lt;data encoding="base64"&gt; R0lGODlhEAAQAPMAMcDAwP/crv/erbigfVdLOyslHQAAAAECAwECAwECAwECAwECAwECAwECAwEC AwECAyH/C01TT0ZGSUNFOS4wGAAAAAxtc09QTVNPRkZJQ0U5LjAHgfNAGQAh/wtNU09GRklDRTku MBUAAAAJcEhZcwAACxMAAAsTAQCanBgAIf8LTVNPRkZJQ0U5LjATAAAAB3RJTUUH1AkWBTYSQXe8 fQAh+QQBAAAAACwAAAAAEAAQAAADSQhgpv7OlDGYstCIMqsZAXYJJEdRQRWRrHk2I9t28CLfX63d ZEXovJ7htwr6dIQB7/hgJGXMzFApOBYgl6n1il0Mv5xuhBEGJAAAOw== &lt;/data&gt; &lt;mime&gt;image/gif&lt;/mime&gt; &lt;resource-attributes&gt; &lt;file-name&gt;clip_image001.gif&lt;/file-name&gt; &lt;/resource-attributes&gt; &lt;/resource&gt; &lt;/note&gt; &lt;/en-export&gt; </code></pre> <hr /> <h1>Implemented solution</h1> <p>Using concept of the solution suggested by <a href="https://stackoverflow.com/users/91822/jackem">Jackem</a>. The main difference is that I avoid creating my own Java class (and creating an extra dependency). I do the processing within the XSLT, since it's straight forward enough, <em>only referencing</em> external dependencies that come with the basic Java libraries.<br> Jackem's solution is <em>more correct</em> because it doesn't lose the leading zero in some hashes, however I found that it was much easier to take care of this elsewhere using li'l basic hackery.</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" ... xmlns:md5="java.security.MessageDigest" xmlns:bigint="java.math.BigInteger" exclude-result-prefixes="md5 bigint"&gt; ... &lt;xsl:for-each select="resource"&gt; &lt;xsl:variable name="md5inst" select="md5:getInstance('MD5')" /&gt; &lt;xsl:value-of select="md5:update($md5inst, $b64bin)" /&gt; &lt;xsl:variable name="imgmd5bytes" select="md5:digest($md5inst)" /&gt; &lt;xsl:variable name="imgmd5bigint" select="bigint:new(1, $imgmd5bytes)" /&gt; &lt;xsl:variable name="imgmd5str" select="bigint:toString($imgmd5bigint, 16)" /&gt; &lt;!-- NOTE: $imgmd5str loses the leading zero from imgmd5bytes (if there is one) --&gt; &lt;/xsl:for-each&gt; ... </code></pre> <p>P.S. see <a href="https://stackoverflow.com/questions/1684909/xslt-convert-base64-data-into-image-files">sibling question</a> for my implementation of of the <code>base64--&gt;image file</code> conversion</p> <p><hr /> This question is a subquestion of <a href="https://stackoverflow.com/questions/1642104/evernote-export-format-enex-to-html-including-pictures">another question I have asked previously</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload