0

I have two different xslts performing two different tasks. I have a requirement to create a single xslt performing both the tasks. Please see bwloe the codes for both the xslts and let mw know if they can be combined into a single xslt.

The first xsl is posting the request to a url using dp url open. The second xsl is searching for a tag in the request and if that tag is present,The tag will be encrypted.

I am looking to do both these tasks in a single xslt ie. look for the tag, encrypt it, post the request(with encrypted tag if it is present) to the url.

 <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" xmlns:env="http://schemas.xmlsoap.org/soap/envelope"
extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">

<xsl:template match="/">

    <xsl:variable name="result">
        <dp:url-open target="{$URL}" response="responsecode-ignore" ssl-proxy="BlankSSL" 
            data-type="xml" http-method="post" timeout="30">
            <xsl:copy-of select="." />
        </dp:url-open>
    </xsl:variable>
</xsl:template>

AND

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" xmlns:env="http://schemas.xmlsoap.org/soap/envelope"
extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">




<xsl:template match="@*|node()">
<xsl:copy>
    <xsl:apply-templates select="@*|node()" />
</xsl:copy>


</xsl:template>


  <xsl:template match="/*[local-name()='Envelope']/*[local-name()='accountNumber']">
  <xsl:copy>
  <xsl:value-of select="dp:encrypt-string('http://www.w3.org/2001/04/xmlenc#tripledes-cbc','hex:1728289',/*[local-name()='Envelope']/*[local-name()='accountNumber'])"/>
  </xsl:copy>
  </xsl:template>
anky316
  • 21
  • 5

1 Answers1

0

You have tagged the question as XSLT 2.0 so if you are really using an XSLT 2.0 processor you can simply process the variable with e.g.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" xmlns:env="http://schemas.xmlsoap.org/soap/envelope"
extension-element-prefixes="dp" exclude-result-prefixes="dp" version="1.0">

<xsl:variable name="first-step">
   <xsl:apply-templates/>
</xsl:variable>

<xsl:template match="/">

    <xsl:variable name="result">
        <dp:url-open target="{$URL}" response="responsecode-ignore" ssl-proxy="BlankSSL" 
            data-type="xml" http-method="post" timeout="30">
            <xsl:copy-of select="$first-step" />
        </dp:url-open>
    </xsl:variable>

    <xsl:apply-templates select="$result/*"/>
</xsl:template>


<xsl:template match="@*|node()">
<xsl:copy>
    <xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:template>


  <xsl:template match="/*[local-name()='Envelope']/*[local-name()='accountNumber']">
  <xsl:copy>
  <xsl:value-of select="dp:encrypt-string('http://www.w3.org/2001/04/xmlenc#tripledes-cbc','hex:1728289',/*[local-name()='Envelope']/*[local-name()='accountNumber'])"/>
  </xsl:copy>
  </xsl:template>
Martin Honnen
  • 160,499
  • 6
  • 90
  • 110
  • DataPower is an odd duck in this regard. The processor is XSLT 1.0 with just enough exceptions to confuse everyone. One of those exceptions is that it *does* do the automatic result-fragment to node-set conversion, so Martin's XSLT 2.0 code should work on DataPower. – bjimba Apr 04 '16 at 18:49
  • Although the above xslt is not throwing any syntax error on datapower, It is not what i am looking for. I want the output of second xsl which is doing the encryption to be the input of first xsl which is sending the input request to the URL specified. In Datapower, I am using two xsl transform actions where i can easily do this by using INPUT and OUTPUT contexts. But here i want to do this using a single xsl transform , hence a single xslt. – anky316 Apr 05 '16 at 10:40
  • @anky316, I have changed the snippet as I misunderstood what you want and the previous suggestion fed the result of the first stylesheet as an input to the second. As all the code seems to be datapower specific, I have no way to test, so try yourself. – Martin Honnen Apr 05 '16 at 11:03
  • @MartinHonnen It works as expected. Thanks for the help. Cheers! – anky316 Apr 05 '16 at 11:29