geddie2001 has asked for the wisdom of the Perl Monks concerning the following question:
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]); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: LibXML setNodeName error
by choroba (Cardinal) on Jun 26, 2017 at 16:26 UTC | |
by geddie2001 (Novice) on Jun 26, 2017 at 16:42 UTC | |
by haukex (Archbishop) on Jun 26, 2017 at 17:10 UTC | |
by geddie2001 (Novice) on Jun 26, 2017 at 17:47 UTC | |
by geddie2001 (Novice) on Jun 26, 2017 at 20:07 UTC | |
by haukex (Archbishop) on Jun 26, 2017 at 20:32 UTC | |
| |
by Anonymous Monk on Jun 27, 2017 at 15:56 UTC |