use strict; use warnings; use XML::LibXML; my $reader = XML::LibXML->load_xml(location => "test.xsl") or die "cannot read input file\n"; my $xpath_context = XML::LibXML::XPathContext->new($reader); foreach my $element_node ($xpath_context -> findnodes('//xsl:element')) { my @attributes = $element_node -> attributes(); $element_node -> setNodeName($attributes[0]); }