title: Python: Generate xml using xml & xslt file
body: <p>I would like to generate an xml using an input xml and a xslt file.  I have a sample input xml and xslt files here &lt;<a href="https://xsltfiddle.liberty-development.net/aiyned/1" rel="nofollow noreferrer">https://xsltfiddle.liberty-development.net/aiyned/1</a>&gt;.  And the final output is what I would like.</p>
  <p>Basically the input.xml is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot; ?&gt;
  &lt;root&gt;
      &lt;parent1 value=&quot;parent1&quot;&gt;
          &lt;inserthere value=&quot;parent1&quot;/&gt;
      &lt;/parent1&gt;
      &lt;parent2 value=&quot;parent2&quot;&gt;
          &lt;inserthere value=&quot;parent2&quot;/&gt;
      &lt;/parent2&gt;
  &lt;/root&gt;
  </code></pre>
  <p>input.xslt is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
  &lt;xsl:stylesheet xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;
      version=&quot;1.0&quot;&gt;
      
    &lt;xsl:output method=&quot;xml&quot;/&gt;
    
    &lt;!-- &lt;xsl:variable name=&quot;childDoc&quot; select=&quot;document('child.xml')&quot;/&gt; --&gt;
    &lt;xsl:variable name=&quot;childDoc&quot;&gt;
      &lt;root&gt;
        &lt;child1 value=&quot;child1&quot;/&gt;
        &lt;child2 value=&quot;child2&quot;/&gt;
      &lt;/root&gt;
    &lt;/xsl:variable&gt;
  
    &lt;xsl:template match=&quot;@*|node()&quot;&gt;
      &lt;xsl:copy&gt;
        &lt;xsl:apply-templates select=&quot;@*|node()&quot;/&gt;
      &lt;/xsl:copy&gt;
    &lt;/xsl:template&gt;
    
    &lt;xsl:template match=&quot;inserthere&quot;&gt;
      &lt;xsl:variable name=&quot;currentParent&quot; select=&quot;.&quot;/&gt;
        &lt;xsl:for-each select=&quot;$childDoc/root/node()&quot;&gt;
          &lt;xsl:copy&gt;
            &lt;xsl:attribute name=&quot;value&quot; select=&quot;concat($currentParent/@value,'_',@value)&quot;/&gt;
          &lt;/xsl:copy&gt;
        &lt;/xsl:for-each&gt;
    &lt;/xsl:template&gt;
    
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  <p>Output xml is:</p>
  <pre><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&lt;root&gt;
      &lt;parent1 value=&quot;parent1&quot;&gt;
          &lt;child1 value=&quot;parent1_child1&quot;/&gt;
          &lt;child2 value=&quot;parent1_child2&quot;/&gt;
      &lt;/parent1&gt;
      &lt;parent2 value=&quot;parent2&quot;&gt;
          &lt;child1 value=&quot;parent2_child1&quot;/&gt;
          &lt;child2 value=&quot;parent2_child2&quot;/&gt;
      &lt;/parent2&gt;
  &lt;/root&gt;
  </code></pre>
  <p>The problem is the site is using saxon engine, which I believe could require a license.  I would like to generate the output xml using lxml or any python library that is free. Currently when I run</p>
  <pre><code>import lxml.etree as ET
  
  dom = ET.parse(&quot;input.xml&quot;)
  xslt = ET.parse(&quot;input.xslt&quot;)
  transform = ET.XSLT(xslt)
  newdom = transform(dom)
  print(ET.tostring(newdom, pretty_print=True))
  </code></pre>
  <p>I get an error of:</p>
  <pre><code>    newdom = transform(dom)
    File &quot;src/lxml/xslt.pxi&quot;, line 602, in lxml.etree.XSLT.__call__
  lxml.etree.XSLTApplyError: Failed to evaluate the 'select' expression.
  </code></pre>
  <p>I think the problem is lxml only support version 1.0? There are some comments here how to use saxon <a href="https://stackoverflow.com/questions/29443364/use-saxon-with-python">use saxon with python</a>, but I would like to prevent requiring java or other external applications.  Is there a way to make the above work with just python? Or is there a way to update my xslt file so that it will work with just lxml transform function?</p>