def test_xslt_xinclude_tg_20010628(): _run_html( source_xml = """\ <?xml version="1.0" encoding="iso-8859-1"?> <html xmlns:xinclude="http://www.w3.org/2001/XInclude"> <head> <title>MyTitle</title> </head> <body> <xinclude:include href="%(uri)s"/> </body> </html>""" % {'uri' : INCLUDE_URI}, transform_xml = """\ <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xinclude="http://www.w3.org/2001/XInclude"> <xsl:output method="html" indent="yes" encoding="iso-8859-1"/> <!-- copy source nodes to result nodes --> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="body"> <body bgcolor='#ffbf00'> <xsl:apply-templates/> <xinclude:include href="%(uri)s"/> </body> </xsl:template> </xsl:stylesheet> """ % {'uri' : INCLUDE_URI}, expected = """\ <html xmlns:xinclude="http://www.w3.org/2001/XInclude"> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <title>MyTitle</title> </head> <body bgcolor='#ffbf00'> <p xml:base="%(base)s"> some text </p> <p xml:base="%(base)s"> some text </p> </body> </html>""" % {'base' : INCLUDE_URI}, )
def test_xslt_include_with_variables_dm_20010506(): try: _run_html(source_xml=commonsource, transform_uri=iri.os_path_to_uri(__file__), transform_xml="""<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:include href="dm_20010506-1.xslt"/> <xsl:variable name="section.autolabel" select="1" /> <xsl:variable name="html.stylesheet">book.xsl</xsl:variable> <xsl:variable name="html.stylesheet.type">text/css</xsl:variable> </xsl:stylesheet>""", expected=None) except XsltError, err: assert err.code == XsltError.DUPLICATE_TOP_LEVEL_VAR, err
def test_xslt_include_with_variables_dm_20010506(): try: _run_html( source_xml = commonsource, transform_uri = iri.os_path_to_uri(__file__), transform_xml = """<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:include href="dm_20010506-1.xslt"/> <xsl:variable name="section.autolabel" select="1" /> <xsl:variable name="html.stylesheet">book.xsl</xsl:variable> <xsl:variable name="html.stylesheet.type">text/css</xsl:variable> </xsl:stylesheet>""", expected = None) except XsltError, err: assert err.code == XsltError.DUPLICATE_TOP_LEVEL_VAR, err
def test_xslt_import_with_params_dm_20010506(): _run_html( source_xml=commonsource, transform_uri=iri.os_path_to_uri(__file__), transform_xml="""<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:import href="dm_20010506-1.xslt"/> <xsl:param name="section.autolabel" select="1" /> <xsl:param name="html.stylesheet">book.xsl</xsl:param> <xsl:param name="html.stylesheet.type">text/css</xsl:param> </xsl:stylesheet>""", expected="""\ <html> START <link type='text/css' rel='stylesheet' href='book.xsl'> END </html>""", )
def test_xslt_import_with_params_dm_20010506(): _run_html( source_xml = commonsource, transform_uri = iri.os_path_to_uri(__file__), transform_xml = """<?xml version="1.0"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:import href="dm_20010506-1.xslt"/> <xsl:param name="section.autolabel" select="1" /> <xsl:param name="html.stylesheet">book.xsl</xsl:param> <xsl:param name="html.stylesheet.type">text/css</xsl:param> </xsl:stylesheet>""", expected = """\ <html> START <link type='text/css' rel='stylesheet' href='book.xsl'> END </html>""", )
def test_xslt_order_dependence_dg_20010503(): _run_html( source_xml="""\ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <?xml-stylesheet type="text/xml" href="Xml/Xslt/Core/addr_book1.xsl"?> <ADDRBOOK> <ENTRY ID="pa"> <NAME>Pieter Aaron</NAME> <ADDRESS>404 Error Way</ADDRESS> <PHONENUM DESC="Work">404-555-1234</PHONENUM> <PHONENUM DESC="Fax">404-555-4321</PHONENUM> <PHONENUM DESC="Pager">404-555-5555</PHONENUM> <EMAIL>[email protected]</EMAIL> </ENTRY> </ADDRBOOK> """, # This test previously did not work, with the error # XsltError: No stylesheets to process. # The problem is the stylesheet is a link in the source XML. # I upgraded the tests, but still don't know how to handle this case. transform_xml=None, expected="""<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <title>Address Book</title> </head> <body> <h1>Tabulate Just Names and Phone Numbers</h1> <table> <tr> <td align='center'><b>Pieter Aaron</b></td> <td>(Work) 404-555-1234<br>(Fax) 404-555-4321<br>(Pager) 404-555-5555</td> </tr> </table> </body> </html>""")
def test_xslt_order_dependence_dg_20010503(): _run_html( source_xml = """\ <?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?> <?xml-stylesheet type="text/xml" href="Xml/Xslt/Core/addr_book1.xsl"?> <ADDRBOOK> <ENTRY ID="pa"> <NAME>Pieter Aaron</NAME> <ADDRESS>404 Error Way</ADDRESS> <PHONENUM DESC="Work">404-555-1234</PHONENUM> <PHONENUM DESC="Fax">404-555-4321</PHONENUM> <PHONENUM DESC="Pager">404-555-5555</PHONENUM> <EMAIL>[email protected]</EMAIL> </ENTRY> </ADDRBOOK> """, # This test previously did not work, with the error # XsltError: No stylesheets to process. # The problem is the stylesheet is a link in the source XML. # I upgraded the tests, but still don't know how to handle this case. transform_xml = None, expected = """<html> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1'> <title>Address Book</title> </head> <body> <h1>Tabulate Just Names and Phone Numbers</h1> <table> <tr> <td align='center'><b>Pieter Aaron</b></td> <td>(Work) 404-555-1234<br>(Fax) 404-555-4321<br>(Pager) 404-555-5555</td> </tr> </table> </body> </html>""")
def test_borrowed(source_xml=source_xml, transform_xml=transform_xml, expected=expected_html): _run_html(source_xml=inputsource(source_xml), transform_xml=inputsource(transform_xml), expected=inputsource(expected).stream.read())
def test_borrowed(source_xml=source_xml, transform_xml=transform_xml, expected=expected_html): _run_html( source_xml = inputsource(source_xml), transform_xml = inputsource(transform_xml), expected = inputsource(expected).stream.read())