def generate_skeleton ( context ): context . html = new_tag_node ( "html" , namespace = 'http://www.w3.org/1999/xhtml' , children = ( tag ( "head" , tag ( "title" , "Testing XML Example" )), tag ( "body" , ( tag ( "h1" , "Persons" ), tag ( "ul" ) )), ) ) def extract_person ( node : TagNode , persons ): persons . append ( ( first ( node . css_select ( "name" )) . full_text , first ( node . css_select ( "family-name" )) . full_text ) ) def list_persons ( previous_result , html : TagNode ): first ( html . css_select ( "html|body html|ul" )) . append_child ( * ( html . new_tag_node ( "li" , children = [ f '{x[1]}, {x[0]}' ]) for x in previous_result ) ) transformation = Transformation ( generate_skeleton , Rule ( 'person' , extract_person ), lib . sort ( 'persons' , itemgetter ( 1 )), list_persons , result_object = 'context.html' , context = { 'persons' : []}) # that's four lines more LOC than the XSLT implementation