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
Post a Comment