Next / Previous / Contents / TCC Help System / NM Tech homepage

15. Test driver for multiple namespaces: crens

This script, crens, tests the xml4create.py module's facilities for creating elements and attributes in multiple namespaces.

crens
#!/usr/bin/env python
#================================================================
# crens: Namespace output testing for pyxml4.py.
# For documentation, see:
#    http://www.nmt.edu/tcc/help/pubs/pyxml4/
#----------------------------------------------------------------

import xml4create as xc

nsMap = { None:   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd",
         "xsl":  "http://www.w3.org/1999/XSL/Transform",
         "exsl": "http://exslt.org/common" }

doc = xc.Document ( "xsl:stylesheet", nsMap=nsMap )
doc.root['version'] = '1.0'

template = xc.Element ( doc.root, 'xsl:template', match='foo' )

subdoc = xc.Element ( template, 'exsl:document', href='outer.html' )

hr = xc.Element ( subdoc, 'hr' )
hr['exsl:class'] = 'silly'

doc.write()

Here's the output (slightly reformatted to fold some long lines):

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet 
     xmlns="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
     xmlns:exsl="http://exslt.org/common"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
     version="1.0">
  <xsl:template match="foo">
    <exsl:document href="outer.html">
      <hr exsl:class="silly"/>
    </exsl:document>
  </xsl:template>
</xsl:stylesheet>