0

I need the following behavior in a XSLT Transformation in Datapower:

Input text:

AAAAAZZZZZZZ
BBBBBZZZZZZZ
CCCCCZZZZZZZ

Output text:

_HEADER
AAAAA
BBBBB
CCCCC
_FOOTER

So I wrote the following XSLT:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dp="http://www.datapower.com/extensions"
  xmlns:str="http://exslt.org/strings"
  xmlns:date="http://exslt.org/dates-and-times"
  extension-element-prefixes="dp str date"
>
  <dp:input-mapping  href="store:///pkcs7-convert-input.ffd" type="ffd"/>

  <xsl:output method="text"/>

  <xsl:variable name="rowsep" select="'&#10;'"/>
  <xsl:variable name="input64" select="dp:binary-encode(/object/message/node())"/> 
   <xsl:variable name="str" select="dp:decode($input64,'base-64')"/>

  <xsl:template match="/">

    <!-- Header -->

    <xsl:text>_HEADER&#10;</xsl:text>

    <!-- Body -->

      <xsl:for-each select="str:split($str,$rowsep)">
        <xsl:if test="position()!=last()">
            <xsl:value-of select="substring(.,1,5)"/>
            <xsl:text>&#10;</xsl:text>
        </xsl:if>
      </xsl:for-each>

      <!-- Trailer -->  

    <xsl:text>_FOOTER&#10;</xsl:text>

</xsl:template>  
</xsl:stylesheet>

But it is generating the following output:

_HEADER
_HEAD
AAAAA
BBBBB
CCCCC
_FOOTER

I don't understand why every text or value-of tag outside the for-each tag generates strange outputs (or at least I'm not able to find a pattern of what's wrong). As you can see, the header is "partially" repeated, and has no clue the reason of this behavior.

Could you please give me some hints on where the mistake would be?

brokermq
  • 97
  • 1
  • 4
  • 15
  • Your XSLT stylesheet as you show it here exposes that behavior? If so, can you include the value of `$str`? – Tomalak Apr 05 '15 at 23:02
  • $str is /object/message/node(), that represents the whole input content: – brokermq Apr 05 '15 at 23:07
  • 1
    I was able to run your code on a DataPower vm and get the expected results. Your best bet is probably to debug by adding an `xsl:value-of` line that outputs the contents of $input64, and then going to some online Base64 converter and seeing if you are actually getting the input data correctly (including the line endings). – bjimba Apr 06 '15 at 18:03
  • Thanks @bjimba, seems to be fine, line endings included. What I see is a kind of buffering in the behavior, as you can see, the _HEADER is stored as the first element of the for each... How exactly are you testing this scenario in your DP? I'm, using a Multiprotocol Gateway, request and response type as non-XML. – brokermq Apr 06 '15 at 19:28
  • I was using an XMLFW with Non-XML request and Loopback. Processing policy has one rule (client to server), and the only actions on the rule are a "transform binary" with your exact XSL code, and a results action. I used curl to send the input: `curl --data-binary @nonxml-in.txt http://mydphost:8009/` Have you turned on the probe? What's your input context look like? – bjimba Apr 07 '15 at 13:12
  • Thanks @bjimba. Just posted the answer. Thanks a lot for your help. – brokermq Apr 07 '15 at 17:55

1 Answers1

0

Solved!... It was my fault... I was closed in the idea that was the XSLT that was failing. But I was applying twice the transformation: in the MPG and in the backend. That explains the strange behavior.

brokermq
  • 97
  • 1
  • 4
  • 15