in reply to Re^5: LibXML setNodeName error
in thread LibXML setNodeName error

You are correct when I'm referring to an example like:
<xsl:element name = "{foo}bar">
In this instance, I would like that node to be left alone, unchanged. test input:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <xsl:element name="foo"> <xsl:element name="{bar}"/> </xsl:element> </xsl:stylesheet>
test output:
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" versi +on="1.0"> <foo> <xsl:element name="{bar}"/> </xsl:element> </foo> </xsl:stylesheet>
I'm sorry for changing the requirements.

Replies are listed 'Best First'.
Re^7: LibXML setNodeName error
by haukex (Archbishop) on Jun 26, 2017 at 20:59 UTC

    Well, in that case perhaps add next unless $el->getAttribute('name')=~/^\w+$/; into the loop I showed, or, since that might reject valid element names, reject the unwanted names with next if $el->getAttribute('name')=~/[\{\}]/;, adding more there as necessary.

    (Looking back at the original problem statement, I do have to say I'm not sure why you want to manipulate your XSL like this in the first place. XML and especially XSL is somewhat verbose in its nature...)

      Perfect! One last request, if that's okay. How do I print to a file instead of the console? I hope this isn't too difficult to solve. I'm currently trying it myself. I will comment as soon as I have it figured out.

        A thorough read of XML-LibXML is probably in order - long, I know, but that's the best way to learn about all the possibilities that are offered :-)

        In this case, have a look at ->toFile in XML::LibXML::Document.