Hi All,

The below is the value of the variable when used with apply templates

<results multiple-outputs="true" transactional="true"
xmlns:v12=""
xmlns:v1=""
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
>
<url input="multi-request-A">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
<url input="multi-request-A">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
<url input="multi-request-A">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
</results>

The below is the value of a variable without apply templates and using for each

<results multiple-outputs="true" transactional="true">
<url input="multi-request-A">http://127.0.0.1:2026/ICS/CustomerProvider/v1</url>
<url input="multi-request-A">http://127.0.0.1:2027/ICS/CustomerProvider/v1</url>
<url input="multi-request-A">http://127.0.0.1:2028/ICS/CustomerProvider/v1</url>
</results>

How can i remove the namespaces coming when using apply templates


The xsl with apply templates

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

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">

        <xsl:apply-templates select="soapenv:Envelope/soapenv:Body/v1:CustomerServicegetCustomerInfoRequest1"/>

    </xsl:template>
    <xsl:template match="v1:CustomerServicegetCustomerInfoRequest1">
        <xsl:apply-templates select="v12:getCustomerInfoParameters"/>
    </xsl:template>



    <xsl:template match="v12:getCustomerInfoParameters">
        <xsl:apply-templates select="v12:customerInfoSearchKey/v12:cardNO"/>
    </xsl:template>


    <xsl:template match="v12:cardNO">


        <xsl:if test="position() = 1" >
            <xsl:variable name="request-A">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-A'" value="$request-A"/>
        </xsl:if>
        <xsl:if test="position() = 2" >
            <xsl:variable name="request-B">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-B'" value="$request-B"/>
        </xsl:if>
        <xsl:if test="position() = 3" >
            <xsl:variable name="request-C">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-C'" value="$request-C"/>
        </xsl:if>

        <xsl:if test="position() = 4" >
            <xsl:variable name="request-D">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-D'" value="$request-D"/>
        </xsl:if>

        <xsl:if test="position() = 5" >
            <xsl:variable name="request-E">
                <xsl:copy-of select="*[local-name() = 'customerInfoSearchKey']"/>
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-E'" value="$request-E"/>
        </xsl:if>

        <xsl:if test="position() = 6" >
            <xsl:variable name="request-F">
                <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
                    <soapenv:Header>
                        <v1:RequestHeader>
                            <v11:correlationID>Corr12345678912345678912</v11:correlationID>
                            <v11:userId>Rejeesh</v11:userId>
                            <v11:sORRegionToken>
                                <v11:automationID/>
                                <v11:sORRegionID/>
                            </v11:sORRegionToken>
                        </v1:RequestHeader>
                    </soapenv:Header>
                    <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
                        <v1:CustomerServicegetCustomerInfoRequest1>
                            <v12:getCustomerInfoParameters>
                                <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
                                <v12:customerInfoSearchKey>
                                    <v12:cardNO>
                                        <xsl:value-of select="*/*[local-name()='cardNO']"/>
                                    </v12:cardNO>
                                </v12:customerInfoSearchKey>
                                <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
                            </v12:getCustomerInfoParameters>
                        </v1:CustomerServicegetCustomerInfoRequest1>
                    </soapenv:Body>
                </soapenv:Envelope>
            </xsl:variable>
            <dp:set-variable name="'var://context/multi-request-F'" value="$request-F"/>
        </xsl:if>


        <xsl:variable name="request-targets">
            <results multiple-outputs="true" transactional="true">
                <xsl:if test="dp:variable('var://context/multi-request-A')">
                    <url input="multi-request-A">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-A">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-A">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
                <xsl:if test="dp:variable('var://context/multi-request-B')">
                    <url input="multi-request-B">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-B">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-B">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
                <xsl:if test="dp:variable('var://context/multi-request-C')">
                    <url input="multi-request-C">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-C">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-C">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
                <xsl:if test="dp:variable('var://context/multi-request-D')">
                    <url input="multi-request-D">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-D">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-D">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
                <xsl:if test="dp:variable('var://context/multi-request-E')">
                    <url input="multi-request-E">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-E">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-E">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
                <xsl:if test="dp:variable('var://context/multi-request-F')">
                    <url input="multi-request-F">http://127.0.0.1:2022/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-F">http://127.0.0.1:2023/ICS/CustomerProvider/v1</url>
                    <url input="multi-request-F">http://127.0.0.1:2024/ICS/CustomerProvider/v1</url>
                </xsl:if>
            </results>
        </xsl:variable>

        <dp:set-variable name="'var://context/multi-request/targets'" value="$request-targets"/>


    </xsl:template>

</xsl:stylesheet>

xml

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="" xmlns:v11="" xmlns:v12="">
   <soapenv:Header>
      <v1:RequestHeader>
         <v11:correlationID>Corr12345678912345678912</v11:correlationID>
         <v11:userId>Rejeesh</v11:userId>
         <v11:sORRegionToken>
            <v11:automationID/>
            <v11:sORRegionID/>
         </v11:sORRegionToken>
      </v1:RequestHeader>
   </soapenv:Header>
   <soapenv:Body wsu:Id="id-35" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
      <v1:CustomerServicegetCustomerInfoRequest1>
         <v12:getCustomerInfoParameters>
            <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
            <v12:customerInfoSearchKey>
               <v12:cardNO>373560012861003</v12:cardNO>
            </v12:customerInfoSearchKey>
            <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
         </v12:getCustomerInfoParameters>
         <v12:getCustomerInfoParameters>
            <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
            <v12:customerInfoSearchKey>
               <v12:cardNO>373560012861004</v12:cardNO>
            </v12:customerInfoSearchKey>
            <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
         </v12:getCustomerInfoParameters>
       <v12:getCustomerInfoParameters>
            <v12:customerInfoTypeSelectionCD>CustomerInfo</v12:customerInfoTypeSelectionCD>
            <v12:customerInfoSearchKey>
               <v12:cardNO>373560012861005</v12:cardNO>
            </v12:customerInfoSearchKey>
            <v12:cardSelectionCD>AllCards</v12:cardSelectionCD>
         </v12:getCustomerInfoParameters>
      </v1:CustomerServicegetCustomerInfoRequest1>
   </soapenv:Body>
</soapenv:Envelope>

Dani AI

Generated

A short diagnosis and practical options (builds on ’s suggestion).

The extra xmlns:… attributes appear because namespace nodes are part of the in‑scope namespaces for result-tree fragments and literal result elements. When the templates create soapenv/v1/v12 elements inside variables, those namespace bindings become in‑scope and the processor will place the declarations on the nearest serialized element (the outer <results>). That explains why the same data built with a different flow (for‑each) can serialize without those declarations, while the apply‑templates path pulls the namespace nodes up.

Quick fixes and robust alternatives

  • Quick: add an exclude list on the stylesheet so prefixes declared in the stylesheet but not needed in the final wrapper are not emitted. For example:
    exclude-result-prefixes="soapenv v1 v11 v12"
    This is the direct idea from and usually removes the unwanted xmlns:* attributes when those prefixes aren’t actually used in the <results> fragment.

  • If the soap envelopes must be preserved (i.e., those envelopes are real nodes stored in variables), the namespaces are required for those nodes and will be emitted somewhere. In that case either:

    • keep the envelopes separate and only build the <results> wrapper from plain strings/URLs (so no soap prefixes are in scope for the wrapper), or
    • convert the stored fragments to node-sets (processor-specific, e.g. exsl:node-set() or vendor extension) and rebuild the output with fresh elements in no namespace.
  • To strip namespaces programmatically, rebuild elements using local-name() so new elements have no prefixes. Example template to copy an input tree with namespaces removed:

<xsl:template match="*">
  <xsl:element name="{local-name()}">
    <xsl:apply-templates select="@*|node()"/>
  </xsl:element>
</xsl:template>

<xsl:template match="@*">
  <xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="text()|comment()|processing-instruction()">
  <xsl:copy/>
</xsl:template>

Troubleshooting tips: inspect serialized values of the intermediate variables to see which prefixes are present, and add only those prefixes to exclude-result-prefixes that are truly unused by the final wrapper. On DataPower the dp:set-variable/dp:variable() behavior can affect whether fragments are serialized or treated as node-sets, so if exclude-result-prefixes has no effect, reconstructing the wrapper from node content (or stripping namespaces as above) is the reliable approach.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.