Hi, Oleg Tkachenko!
*** Thanks for you help!
*** I've tried the method you told me, it works! but there is still a problem need you help.
my source xml file is like this:
<?xml version="1.0" encoding="utf-8"?>
<s:root xmlns:s="urn:so urce-namespace">
*** <s:mail&g t;
*** ** <s:subject&g t;xxxx</s:subject>
*** ** <s:from>x xxx</s:from>
*** ** <s:to>xxx x</s:to>
*** ** <s:content&g t;
*** ** <![CDATA[xxxxxxxxx]]>
*** ** </s:content>
*** </s:mail>
</s:root>
my transform file:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesh eet version="1.0"
*** *** xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
*** *** xmlns:s="urn:so urce-namespace"
*** *** xmlns="urn:targ et-namespace">
*** <xsl:templat e match="/">
*** *** <xsl:elem ent name="newmails" >
*** *** *** <xsl:appl y-templates select="//s:mail" />
*** *** </xsl:element>
*** </xsl:template> ;
*** <xsl:templat e match="s:mail"& gt;
*** *** <xsl:elem ent name="newmail"& gt;
*** *** *** <xsl:copy> ;
*** *** *** *** <xsl:appl y-templates select="*"/>
*** *** *** </xsl:copy>
*** *** </xsl:element>
*** </xsl:template> ;
***
*** <xsl:templat e match="s:*">
*** *** <xsl:elem ent name="{local-name()}" namespace="urn: target-namespace">
*** *** *** <xsl:appl y-templates select="@*|node ()"/>
*** *** </xsl:element>
*** </xsl:template> ;
***
</xsl:stylesheet& gt;
the result is:
<?xml version="1.0" encoding="utf-8"?>
<newmails xmlns="urn:targ et-namespace">
*** <newmail& gt;
*** ***
<s:mail xmlns:s="urn:so urce-namespace">
*** *** *** <subject> xxxx</subject>
*** *** *** <from>xxx x</from>
*** *** *** <to>xxxx& lt;/to>
*** *** *** <content> xxxxxxxxx</content>
*** ***
</s:mail>
*** </newmail>
</newmails>
BUT the result I hoped is:
<?xml version="1.0" encoding="utf-8"?>
<newmails xmlns="urn:targ et-namespace">
*** <newmail& gt;
*** *** <subject> xxxx</subject>
*** *** <from>xxx x</from>
*** *** <to>xxxx& lt;/to>
*** *** <content> xxxxxxxxx</content>
*** </newmail>
</newmails>
I DO NOT create the "s:mail" element! Could you tell me how to elimate the "s:mail" element, and why this happened?
Oleg Tkachenko [MVP] 写道: Knighterrant wrote:
I want to copy elements from one namespace to anothor, how to create the xslt?
You have to recreate elements, namespace cannot be changed:
<xsl:stylesh eet version="1.0"
****xmlns:x sl=
"http://www.w3.org/1999/XSL/Transform"
* xmlns:s="urn:so urce-namespace">
* <xsl:templat e match="@*|node( )">
*** <xsl:copy> ;
***** <xsl:appl y-templates select="@*|node ()"/>
*** </xsl:copy>
* </xsl:template> ;
* <xsl:templat e match="s:*">
*** <xsl:elem ent name="t:{local-name()}" namespace="urn: target-namespace">
***** <xsl:appl y-templates select="@*|node ()"/>
*** </xsl:element>
* </xsl:template> ;
</xsl:stylesheet& gt;