<!--
     probe-timestamps.xsl:  

     tool to display timestamp/transaction-id from "Probe Export Capture"

$ coproc2 probe-timestamps.xsl mpgw\@testasync.zip http://dp3-l3:2224
timestamp            tid
==================== ===
2012-10-09T15:03:38Z 7776
2012-10-09T15:09:21Z 11408
2012-10-09T15:09:24Z 11488
2012-10-09T15:10:07Z 3697
$ vi probe-timestamps.xsl
$
-->
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dp="http://www.datapower.com/extensions"
  xmlns:dpfunc="http://www.datapower.com/extensions/functions"
  xmlns:func="http://exslt.org/functions"
  extension-element-prefixes="dp"
>
  <!-- get dpfunc:zulu-time() -->
  <xsl:include href="store:///utilities.xsl"/>


  <!--  ==>  <object><message>***binary data***</message></object>  -->
  <dp:input-mapping  href="store:///pkcs7-convert-input.ffd" type="ffd"/>


  <!-- nice to have functions for dealing with attachments -->
  <func:function name="func:att-man">
    <func:result select="dp:variable('var://context/IN/attachment-manifest')"/>
  </func:function>

  <func:function name="func:cid">
    <xsl:param name="name"/>  <func:result select="concat('cid:',$name)"/>
  </func:function>

  <func:function name="func:att">
    <xsl:param name="name"/>

    <func:result select="concat('attachment://IN/',func:cid($name))"/>
  </func:function>

  <func:function name="func:zip">
    <xsl:param name="name"/> <xsl:param name="fname"/>

    <func:result 
       select="concat(func:att($name),'?Archive=zip&amp;Filename=',$fname)"/>
  </func:function>

  <xsl:variable name="inp" select="'inp'"/>


  <xsl:template match="/">

    <!-- create context "IN" with "any content" (not used) -->
    <dp:set-variable name="'var://context/IN'" value="''" />

    <!-- attach INPUT zip-archive to context "IN" ($inp Content-ID) -->
    <dp:url-open 
      target="{func:att($inp)}" 
      data-type="base64" 
      response="ignore"
      content-type="application/zip"
    >
      <xsl:value-of select="dp:binary-encode(/object/message/node())" />
    </dp:url-open>


    <!-- collect parsed request input context data for each transaction-id -->
    <xsl:variable name="inputs">
      <xsl:for-each
         select="func:att-man()/manifest/attachments
                   /attachment/files/file/filename[contains(.,'/0/0.xml.gz')]"
      >
        <!-- extract "tid/0/0.xml.gz" from zip-archive ... -->
        <xsl:variable name="zip">
          <dp:url-open 
            target="{func:zip($inp, .)}" 
            response="binaryNode"
          />
        </xsl:variable>
  
        <xsl:variable name="content.gz.b64" 
          select="dp:binary-encode($zip/result/binary/node())"/>
 
        <!-- parse the inflated content.gz.b64 --> 
        <xsl:copy-of select="dp:parse(dp:inflate($content.gz.b64,'gzip'))"/>
      </xsl:for-each>
    </xsl:variable>


    <!-- generate table output, sorted by timestamnp -->
    <xsl:text>timestamp            tid&#10;</xsl:text>
    <xsl:text>==================== ===&#10;</xsl:text>

    <xsl:for-each select="$inputs/*/*">
      <xsl:sort select="timestamp"/>

      <xsl:if test="normalize-space(transaction-id)">
        <xsl:value-of select="dpfunc:zulu-time(timestamp div 1000)"/>
        <xsl:text> </xsl:text>
        <xsl:value-of select="transaction-id"/>
        <xsl:text>&#10;</xsl:text>
      </xsl:if>
    </xsl:for-each>

  </xsl:template>

</xsl:stylesheet>