File tree Expand file tree Collapse file tree 3 files changed +21
-8
lines changed
main/java/com/nwalsh/sinclude
test/java/com/nwalsh/sinclude Expand file tree Collapse file tree 3 files changed +21
-8
lines changed Original file line number Diff line number Diff line change 1
1
basename =sinclude
2
2
sincludeTitle =Saxon XInclude
3
- sincludeVersion =5.2.2
3
+ sincludeVersion =5.2.3
4
4
5
5
saxonVersion =11.5
Original file line number Diff line number Diff line change @@ -447,13 +447,26 @@ public XdmNode process(XdmNode node) throws XPathException {
447
447
// spaces off each line. All trailing spaces are stripped, the number of leading
448
448
// spaces is determined by the number of spaces on the first line.
449
449
if (getTrimText () && parse == ParseType .TEXTPARSE ) {
450
- String text = doc .getStringValue ();
451
- String [] lines = text . split ( " \n " , - 1 ); // -1 == include empty trailing strings
450
+ String [] lines = doc .getStringValue (). split ( " \n " , - 1 ); // -1 == include empty trailing strings
451
+
452
452
if (lines .length > 0 ) {
453
- int trimleading = 0 ;
454
- while (trimleading < lines [0 ].length () && lines [0 ].charAt (trimleading ) == ' ' ) {
455
- trimleading ++;
453
+ int trimleading = -1 ;
454
+ for (String line : lines ) {
455
+ // (Effectively) blank lines don't count
456
+ if (!"" .equals (line .trim ())) {
457
+ int leading = 0 ;
458
+ while (leading < line .length () && line .charAt (leading ) == ' ' ) {
459
+ leading ++;
460
+ }
461
+ if (trimleading < 0 || leading < trimleading ) {
462
+ trimleading = leading ;
463
+ }
464
+ if (trimleading == 0 ) {
465
+ break ;
466
+ }
467
+ }
456
468
}
469
+
457
470
XdmDestination destination = ReceiverUtils .makeDestination (doc );
458
471
Receiver receiver = ReceiverUtils .makeReceiver (doc , destination );
459
472
for (int pos = 0 ; pos < lines .length ; pos ++) {
Original file line number Diff line number Diff line change @@ -182,7 +182,7 @@ public class FakeDocumentResolver implements DocumentResolver {
182
182
textMap .put ("one.txt" , "This is line one.\n " );
183
183
textMap .put ("two.txt" , "\n \n \n \n \n \n \n \n \n This is line 10.\n \n \n \n \n This is line 15." );
184
184
textMap .put ("three.xml" , "<doc>Document three.</doc>" );
185
- textMap .put ("four.txt" , " Four leading blanks\n {\n Three leading blanks\n }\n Four leading blanks\n No leading blanks" );
185
+ textMap .put ("four.txt" , " Four leading blanks\n {\n Three leading blanks\n }\n Four leading blanks\n Two leading blanks" );
186
186
}
187
187
188
188
private static Map <String , String > expandedMap = null ;
@@ -318,7 +318,7 @@ public class FakeDocumentResolver implements DocumentResolver {
318
318
"</doc>\n " );
319
319
expandedMap .put ("selfrefloop.xml" , "<doc/>" );
320
320
expandedMap .put ("trimtext.xml" , "<doc xmlns:xi='http://www.w3.org/2001/XInclude'>\n " +
321
- "{\n Three leading blanks\n }\n Four leading blanks\n No leading blanks\n \n " +
321
+ " {\n Three leading blanks\n }\n Four leading blanks\n Two leading blanks\n \n " +
322
322
"</doc>\n " );
323
323
324
324
}
You can’t perform that action at this time.
0 commit comments