I am attempting to write a perl script that reads an xsl document and changes every instance of <xsl:element name =" foobar"> to <foobar> (essentially stripping out the `xsl:element name` so that the code is easier to read)
Here is what I have in `test.xsl`:In `replaceelementname.pl`:<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Tr +ansform"> <xsl:element name="foo"> <xsl:value-of select="bar"/> </xsl:element> </xsl:stylesheet>
The output when I run this script is: bad name at replaceelementname.pl line 12 Any help would be greatly appreciateduse strict; use warnings; use XML::LibXML; my $reader = XML::LibXML->load_xml(location => "test.xsl") or die "can +not 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]); }
In reply to LibXML setNodeName error by geddie2001
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |