@@ -798,7 +798,7 @@ function xinclude_run_byid( DOMDocument $dom )
798798 $ xpath ->registerNamespace ( "xi " , "http://www.w3.org/2001/XInclude " );
799799 $ xincludes = $ xpath ->query ( "//xi:include " );
800800
801- $ progress = false ;
801+ $ changed = false ;
802802 foreach ( $ xincludes as $ xinclude )
803803 {
804804 $ xpointer = $ xinclude ->getAttribute ( "xpointer " );
@@ -825,13 +825,12 @@ function xinclude_run_byid( DOMDocument $dom )
825825 $ xinclude ->parentNode ->insertBefore ( $ insert , $ xinclude ); // add
826826 $ xinclude ->parentNode ->removeChild ( $ xinclude ); // del
827827
828- $ progress = true ;
829828 $ total ++;
829+ $ changed = true ;
830+ libxml_clear_errors ();
830831 }
831832
832- if ( $ progress )
833- continue ;
834- else
833+ if ( ! $ changed )
835834 return $ total ;
836835 }
837836 echo "XInclude nested too deeply (xml:id). \n" ;
@@ -845,11 +844,11 @@ function xinclude_run_xpointer( DOMDocument $dom ) : int
845844 for ( $ run = 0 ; $ run < $ maxrun ; $ run ++ )
846845 {
847846 echo "$ run " ;
848- libxml_clear_errors ();
849847 $ status = (int ) $ dom ->xinclude ();
850848 if ( $ status <= 0 )
851849 return $ total ;
852850 $ total += $ status ;
851+ libxml_clear_errors ();
853852 }
854853 echo "XInclude nested too deeply (xpointer). \n" ;
855854 errors_are_bad ( -1 );
@@ -866,11 +865,33 @@ function xinclude_report()
866865 $ errors = libxml_get_errors ();
867866 libxml_clear_errors ();
868867
869- if ( count ( $ errors ) > 0 && $ report )
868+ if ( ! $ report )
869+ return ;
870+
871+ $ count = 0 ;
872+ $ prefix = realpath ( __DIR__ );
873+
874+ foreach ( $ errors as $ error )
875+ {
876+ $ msg = $ error ->message ;
877+ $ file = $ error ->file ;
878+ $ line = $ error ->line ;
879+ $ clmn = $ error ->column ;
880+
881+ $ msg = rtrim ( $ msg );
882+ if ( str_starts_with ( $ file , $ prefix ) )
883+ $ file = substr ( $ file , strlen ( $ prefix ) + 1 );
884+
885+ if ( $ count == 0 )
886+ fprintf ( $ output , "\n" );
887+
888+ fprintf ( $ output , "[ {$ file } {$ line }: {$ clmn }] $ msg \n" );
889+ $ count ++;
890+ }
891+
892+ if ( $ count > 0 )
870893 {
871- fprintf ( $ output , "\n\n" );
872- foreach ( $ errors as $ error )
873- fprintf ( $ output , rtrim ( $ error ->message ) . "\n\n" );
894+ fprintf ( $ output , "\n" );
874895 if ( $ fatal )
875896 errors_are_bad ( 1 );
876897 }
0 commit comments