title: Correct way to loop through nested XML tags, map them and casting them using XSLT
body: <p>I am quite new to XSLT and am wrap my head around a problem. I have an XML document which consists of a certain layout. The part where my problem exists is revolved around the following:</p>
  
  <pre><code>&lt;content&gt;
      &lt;body&gt;
          &lt;p&gt;Paragraphs are a possibility&lt;/p&gt;
          &lt;image src="base64-encoded-source" /&gt;
          &lt;image src="another-base64-encoded-source" /&gt;
      &lt;/body&gt;
  &lt;/content&gt;
  </code></pre>
  
  <p>What I am trying to achieve is a proper <code>JSON</code> output using an <code>xsl:map</code> which could look like such:</p>
  
  <pre><code>{
      body-images: [
          "decoded-source",
          "another-decoded-source"
      ]
  }
  </code></pre>
  
  <p>I am using XML files which are in the same folder as the XSLT so I select these beforehand and refer to them using the namespace mechanism. I was originally able to achieve the first step of the above JSON example by using <code>xsl:sequence</code> which for me looked like:</p>
  
  <pre><code>&lt;xsl:if test="not(empty($content/content/body/image))"&gt;
      &lt;xsl:map-entry key="string('body-images')"&gt;
          &lt;xsl:sequence select="array{$content/content/body/image/@src/string()}"/&gt;
      &lt;/xsl:map-entry&gt;
  &lt;/xsl:if&gt;
  </code></pre>
  
  <p>This was perfect, I managed to fill a map key with an array of the sources from the images. This is however where I realized I had to decode the base64 encoded sources which I have tested and am planning on doing using <code>saxon:base64Binary-to-string(xs:base64Binary('source attribute of image goes here'), 'UTF8'))</code>. </p>
  
  <p>This is where I am stuck. I had originally tried to place the base64 decoding in the sequence but my editor gave me a warning that I cannot use that form of casting inside the <code>xsl:sequence</code>. I have then tried looping through the array which the <code>xsl:sequence</code> provided for me using <code>xsl:for-each</code> and trying to select my map key, to then use the base64 decoding on the array results one by one. I was unable to figure out what I had to use as key selector however, as the key used by the map is not originally found in the XML document like my other keys.</p>
  
  <p>If my approach is incorrect to begin with feel free to let me know and point me in the correct direction!</p>