tags:

views:

26

answers:

2
A: 

Your XML isn't valid, but I assume you just've missed the closing TXLifeResponse element.

The following transformation will do what you want:

XML:

<?xml version="1.0" encoding="UTF-8"?>
<ns:TXLife xmlns:ns="http://ACORD.org/Standards/Life/2"&gt;

  <TXLifeResponse>
    <TransRefGUID/>
    <TransExeDate/>
    <TransExeTime/>

    <TransType tc="228"/>
  </TXLifeResponse>

</ns:TXLife>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  xmlns:ns="http://ACORD.org/Standards/Life/2"&gt;

  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
    <soapenv:Envelope 
      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
      xmlns:acor="http://www.foresters.com/esb/ws/wsdl/ACORD-v1.0" 
      xmlns:ns="http://ACORD.org/Standards/Life/2"&gt;
      <soapenv:Header/>
      <soapenv:Body>
        <xsl:copy>
          <xsl:apply-templates/>
        </xsl:copy>
      </soapenv:Body>
    </soapenv:Envelope>
  </xsl:template>

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

  <xsl:template match="@*">
    <xsl:copy-of select="."/>
  </xsl:template>

</xsl:stylesheet>

Output:

<soapenv:Envelope 
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" 
  xmlns:acor="http://www.foresters.com/esb/ws/wsdl/ACORD-v1.0" 
  xmlns:ns="http://ACORD.org/Standards/Life/2"&gt;
  <soapenv:Header/>
  <soapenv:Body>
    <ns:TXLife>
      <ns:TXLifeResponse>
        <ns:TransRefGUID/>
        <ns:TransExeDate/>
        <ns:TransExeTime/>
        <ns:TransType tc="228"/>
      </ns:TXLifeResponse>
    </ns:TXLife>
  </soapenv:Body>
</soapenv:Envelope>

The template xsl:template match="node()[local-name(.) = 'TXLife']" is somewhat strange to me. What are you trying to accomplish? Maybe we can help explain why this isn't the appropriate way to do it.

Per T
because i am doing for particular node 'TXLife'. so that all the child elements of that should have prefixed with 'ns'
Madhu CM
@Per T Thanks a lot
Madhu CM
@Madhu CM: I understand your intention but that matching template will only match one node in your source document, the node with local name `TXLife`, the rest will be processed by the built in template rules. And please mark my answer as a solution if this solved your problem! ;)
Per T
A: 

If you want only TXLife and descendant to be under http://ACORD.org/Standards/Life/2 namespace, use this stylesheet:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ns="http://ACORD.org/Standards/Life/2"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    <xsl:template match="/">
        <soapenv:Envelope>
            <soapenv:Header/>
            <soapenv:Body>
                <xsl:apply-templates/>
            </soapenv:Body>
        </soapenv:Envelope>
    </xsl:template>
    <xsl:template match="*[ancestor-or-self::ns:TXLife]">
        <xsl:element name="ns:{local-name()}">
            <xsl:apply-templates select="@*|node()"/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
</xsl:stylesheet>

Output:

<soapenv:Envelope
 xmlns:ns="http://ACORD.org/Standards/Life/2"
  xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"&gt;
    <soapenv:Header />
    <soapenv:Body>
        <ns:TXLife>
            <ns:TXLifeResponse>
                <ns:TransRefGUID></ns:TransRefGUID>
                <ns:TransExeDate></ns:TransExeDate>
                <ns:TransExeTime></ns:TransExeTime>
                <ns:TransType tc="228"></ns:TransType>
            </ns:TXLifeResponse>
        </ns:TXLife>
    </soapenv:Body>
</soapenv:Envelope>
Alejandro