Re: [xsl] adding element in with general namespace prefix

Subject: Re: [xsl] adding element in with general namespace prefix
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Wed, 08 Feb 2012 17:42:29 -0500
At 2012-02-09 03:46 +0530, ram wrote:
it doesn't worked for me. Can you send across your code for the expected result.

I need to leave my keyboard for the day, so I won't have the chance to respond to your response to my earlier request for guidance as to the problems you are experiencing. I hope the code below helps ... I don't know if it will.


. . . . . . . Ken

t:\ftemp>type ram.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
   xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
   exclude-result-prefixes="soapenv"
  version="1.0">

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

<xsl:template match="soapenv:Header">
  <xsl:copy>
    <xsl:copy-of select="@*"/>
      <wsse:Security
xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";>
        <wsse:UsernameToken>
          <wsse:Username>abcd</wsse:Username>
          <wsse:Password>ramkurra</wsse:Password>
        </wsse:UsernameToken>
      </wsse:Security>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>
t:\ftemp>type ram1.xml
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:con1="http://abc.com/DefService/"; >
        <soapenv:Header>

         </soapenv:Header>
        <soapenv:Body>
                <con1:GetDefinition>
                        <!--Optional:-->
                        <con1:Request><con1:Id/>
                        </con1:Request>
                </con1:GetDefinition>
        </soapenv:Body>
</soapenv:Envelope>

t:\ftemp>call xslt ram1.xml ram.xsl ram1.out

t:\ftemp>type ram1.out
<?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:con1="http://abc.com/DefService/";>
<soapenv:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";><wsse:UsernameToken><wsse:Username>abcd</wsse:Username><wsse:Password>ramkurra</wsse:Password></wsse:UsernameToken></wsse:Security></soapenv:Header>
<soapenv:Body>
<con1:GetDefinition>
<!--Optional:-->
<con1:Request><con1:Id/>
</con1:Request>
</con1:GetDefinition>
</soapenv:Body>
</soapenv:Envelope>
t:\ftemp>type ram2.xml
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/";
xmlns:con1="http://abc.com/DefService/"; >
<s:Header>


         </s:Header>
        <s:Body>
                <con1:GetDefinition>
                        <!--Optional:-->
                        <con1:Request><con1:Id/>
                        </con1:Request>
                </con1:GetDefinition>
        </s:Body>
</s:Envelope>

t:\ftemp>call xslt ram2.xml ram.xsl ram2.out

t:\ftemp>type ram2.out
<?xml version="1.0" encoding="utf-8"?><s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"; xmlns:con1="http://abc.com/DefService/";>
<s:Header><wsse:Security xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd";><wsse:UsernameToken><wsse:Username>abcd</wsse:Username><wsse:Password>ramkurra</wsse:Password></wsse:UsernameToken></wsse:Security></s:Header>
<s:Body>
<con1:GetDefinition>
<!--Optional:-->
<con1:Request><con1:Id/>
</con1:Request>
</con1:GetDefinition>
</s:Body>
</s:Envelope>
t:\ftemp>rem Done!




--
Contact us for world-wide XML consulting and instructor-led training
Free 5-hour video lecture: XSLT/XPath 1.0 & 2.0 http://ude.my/uoui9h
Crane Softwrights Ltd.            http://www.CraneSoftwrights.com/s/
G. Ken Holman                   mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal

Current Thread