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

So you have something like <xsl:element name="foo{bar">? That's not going to be valid as an XML element Name (<foo{bar>?), so what do you want the element to be named instead in that case?

It's not an issue with XML::LibXML, which probably follows the XML spec precisely, but with XML itself. Also, as always, SSCCE - give us the shortest possible code that demonstrates the problem so we can see it.

Replies are listed 'Best First'.
Re^6: LibXML setNodeName error
by geddie2001 (Novice) on Jun 26, 2017 at 20:49 UTC
    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.

      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.