Search code examples
xsltxslt-1.0xslt-2.0ibm-datapower

Combing these two xslts into one


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>

Solution

  • 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>