xml - Copy all Attributes [Not only values of attributes but whole list of attributes] of an element -


i have scenario want copy attributes including namespaces [here mean entire attribute list , namespace list , not values of attributes] xml tag in input xml.

for ex:

input xml:

<?xml version="1.0" encoding="utf-8"?> <enricher>     <result>         <xbrl xmlns="http://www.xbrl.org/2003/instance"          xmlns:idp-com="http://www.dnb.com/idp/common/vers1"          xmlns:idp-enumcom="http://www.dnb.com/idp/common/enumeration/common/vers1"          xsi:schemalocation="http://www.dnb.com/idp/product/common/vers1 ../common/productcommontaxonomy.xsd          http://www.dnb.com/idp/common/vers1 ../../data/common/commontaxonomy.xsd">             <context id="defaulti">                 <entity>                     <identifier scheme="http://www.dnb.com">text</identifier>                 </entity>                 <period>                     <instant>2000-07-14</instant>                 </period>             </context>         </xbrl>     </result> </enricher> 

output xml:

<?xml version="1.0" encoding="utf-8"?> <enricher>     <result>         <xbrlresp xmlns="http://www.xbrl.org/2003/instance"          xmlns:idp-com="http://www.dnb.com/idp/common/vers1"          xmlns:idp-enumcom="http://www.dnb.com/idp/common/enumeration/common/vers1"          xsi:schemalocation="http://www.dnb.com/idp/product/common/vers1 ../common/productcommontaxonomy.xsd          http://www.dnb.com/idp/common/vers1 ../../data/common/commontaxonomy.xsd">             <context id="defaulti">                 <entity>                     <identifier scheme="http://www.dnb.com">text</identifier>                 </entity>                 <period>                     <instant>2000-07-14</instant>                 </period>             </context>         </xbrlresp>     </result> </enricher> 

the output should have <xbrlresp> tag namespaces , attributes of <xbrl>.

extending the answer matthias, if, aesthetic reasons, want copy namespace declarations of xbrl element onto new element you're creating, can using

<xsl:template match="xb:xbrl">   <xsl:element name="xbrlresp" namespace="http://www.xbrl.org/2003/instance">     <xsl:copy-of select="namespace::*" />     <xsl:apply-templates select="@*|node()"/>   </xsl:element> </xsl:template> 

the copy-of copies namespace nodes input xbrl element onto generated xbrlresp, should result in serializer adding namespace declarations.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -