@@ -771,18 +771,43 @@ function individual_xml_broken_check()
771771 }
772772}
773773
774- echo " Expanding XIncludes... " ;
774+ xinclude_no_fallback ( $ dom ) ;
775775
776+ echo "Expanding XIncludes... " ;
776777$ total = xinclude_run_byid ( $ dom );
777778$ total += xinclude_run_xpointer ( $ dom );
778-
779779if ( $ total == 0 )
780780 echo "failed. \n" ;
781781else
782782 echo "done: $ total tags replaced. \n" ;
783783
784784xinclude_residual_fixup ( $ dom );
785785
786+ function xinclude_no_fallback ( DOMDocument $ dom )
787+ {
788+ // Check if there is reachable <xi:fallback>s.
789+ // Not permited in doc-en, warning on translations.
790+
791+ $ xpath = new DOMXPath ( $ dom );
792+ $ xpath ->registerNamespace ( "xi " , "http://www.w3.org/2001/XInclude " );
793+
794+ $ xifallbacks = $ xpath ->query ( "//xi:fallback " );
795+
796+ if ( $ xifallbacks ->length > 0 )
797+ {
798+ if ( $ GLOBALS ['ac ' ]['LANG ' ] == 'en ' )
799+ {
800+ print "\n<xi:fallback> cause silent errors in all languages. \n" ;
801+ print "Not allowed on doc-en. \n" ;
802+ errors_are_bad ( 1 );
803+ }
804+ else
805+ {
806+ print "Translation contains <xi:fallback>. Manual parts will be missing. \n" ;
807+ }
808+ }
809+ }
810+
786811function xinclude_run_byid ( DOMDocument $ dom )
787812{
788813 // libxml does not implements the XInclude 1.1 feature,
@@ -792,8 +817,9 @@ function xinclude_run_byid( DOMDocument $dom )
792817 $ xpath = new DOMXPath ( $ dom );
793818 $ xpath ->registerNamespace ( "xi " , "http://www.w3.org/2001/XInclude " );
794819
795- // Resolve xpointers via a precomputed map; on duplicate xml:ids, first wins.
820+ // Collect IDs in one go. On duplicate xml:ids, first wins.
796821 // Avoids quadratic tree walks (~ 90% performance gain).
822+
797823 $ byId = [];
798824 foreach ( $ xpath ->query ( "//*[@xml:id] " ) as $ node ) {
799825 $ byId [$ node ->getAttribute ("xml:id " )] ??= $ node ;
@@ -873,22 +899,25 @@ function xinclude_residual_fixup( DOMDocument $dom )
873899 $ fixups = 0 ;
874900 $ hardfail = false ;
875901
876- dom_saveload ( $ dom , __DIR__ . "/temp/manual.err " );
902+ dom_saveload ( $ dom , __DIR__ . "/temp/debug.xi " );
877903 $ nodes = xinclude_residual_list ( $ dom );
878904
879905 foreach ( $ nodes as $ node )
880906 {
881907 $ fixup = null ;
882908 $ parent = $ node ->parentNode ->nodeName ;
883909 $ target = $ node ->getAttribute ("xpointer " );
884- $ alert = "[[[Failed XInclude ' $ target']]] " ;
910+ $ alert = "[[[Failed XInclude<!-- $ target --> ']]] " ;
885911
886912 if ( $ fixups === 0 )
887- echo "\nFailed XIncludes, manual parts will be missing. Unresolved xpointers : \n" ;
913+ echo "\nFailed XIncludes, manual parts will be missing. Failed xpointer : \n" ;
888914
889915 echo "- {$ target }\n" ;
890916 $ fixups ++;
891917
918+ // Empty elements are bad in PhD, so filling with $alert.
919+ // See https://github.com/php/phd/issues/181
920+
892921 switch ( $ parent )
893922 {
894923 case "listitem " :
@@ -897,13 +926,13 @@ function xinclude_residual_fixup( DOMDocument $dom )
897926 $ fixup = "" ;
898927 break ;
899928 case "refsect1 " :
900- $ fixup = "<title>_ </title><simpara> $ alert</simpara> " ; // https://github.com/php/phd/issues/181
929+ $ fixup = "<title> $ alert </title><simpara> $ alert</simpara> " ;
901930 break ;
902931 case "tbody " :
903932 $ fixup = "<row><entry> $ alert</entry></row> " ;
904933 break ;
905934 case "variablelist " :
906- $ fixup = "<varlistentry><term></term><listitem><simpara> $ alert</simpara></listitem></varlistentry> " ;
935+ $ fixup = "<varlistentry><term> $ alert </term><listitem><simpara> $ alert</simpara></listitem></varlistentry> " ;
907936 break ;
908937 case "classsynopsis " :
909938 $ fixup = "<classsynopsisinfo role='comment'> $ alert</classsynopsisinfo> " ;
@@ -929,7 +958,7 @@ function xinclude_residual_fixup( DOMDocument $dom )
929958 unset( $ nodes );
930959
931960 if ( $ fixups > 0 )
932- echo "Dumped file: temp/manual.err . Inspect residual xi:include tags in this file. \n\n" ;
961+ echo "Dumped file: temp/debug.xi . Inspect residual xi:include tags in this file. \n\n" ;
933962
934963 if ( $ hardfail )
935964 {
0 commit comments