#NEWLINE# def test_xslt_document_XML_resolver( self ) : #NEWLINE# #INDENT# assertEqual = self . assertEqual #NEWLINE# called = { #NEWLINE# #INDENT# 'count' : 0 , #NEWLINE# #UNINDENT# } #NEWLINE# class TestResolver ( etree . Resolver ) : #NEWLINE# #INDENT# def resolve( self , url , id , context ) : #NEWLINE# #INDENT# assertEqual ( url , 'file://ANYTHING' ) #NEWLINE# called [ 'count' ] += 1 #NEWLINE# return self . resolve_string ( '<CALLED/>' , context ) #NEWLINE# #UNINDENT# #UNINDENT# parser = etree . XMLParser ( ) #NEWLINE# parser . resolvers . add ( TestResolver ( ) ) #NEWLINE# xslt = etree . XSLT ( etree . XML ( _bytes ( '<xsl:stylesheet version="1.0"\n   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"\n   xmlns:l="local">\n  <xsl:template match="/">\n    <test>\n      <xsl:for-each select="document(\'\')//l:data/l:entry">\n        <xsl:copy-of select="document(\'file://ANYTHING\')"/>\n        <xsl:copy>\n          <xsl:attribute name="value">\n            <xsl:value-of select="."/>\n          </xsl:attribute>\n        </xsl:copy>\n      </xsl:for-each>\n    </test>\n  </xsl:template>\n  <l:data>\n    <l:entry>A</l:entry>\n    <l:entry>B</l:entry>\n  </l:data>\n</xsl:stylesheet>\n' ) , parser ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 0 ) #NEWLINE# result = xslt ( etree . XML ( '<a/>' ) ) #NEWLINE# self . assertEqual ( called [ 'count' ] , 1 ) #NEWLINE# root = result . getroot ( ) #NEWLINE# self . assertEqual ( parser . tag , 'test' ) #NEWLINE# self . assertEqual ( len ( root ) , 4 ) #NEWLINE# self . assertEqual ( root [ 0 ] . tag , 'CALLED' ) #NEWLINE# self . assertEqual ( root [ 1 ] . tag , '{local}entry' ) #NEWLINE# self . assertEqual ( root [ 1 ] . text , None ) #NEWLINE# self . assertEqual ( root [ 1 ] . get ( 'value' ) , 'A' ) #NEWLINE# self . assertEqual ( root [ 2 ] . tag , 'CALLED' ) #NEWLINE# self . assertEqual ( root [ 3 ] . tag , '{local}entry' ) #NEWLINE# self . assertEqual ( root [ 3 ] . text , None ) #NEWLINE# self . assertEqual ( root [ 3 ] . get ( 'value' ) , 'B' )