diff --git a/src/Schematron/Formatters/FormattingUtils.cs b/src/Schematron/Formatters/FormattingUtils.cs index 541f331..4dfdd54 100644 --- a/src/Schematron/Formatters/FormattingUtils.cs +++ b/src/Schematron/Formatters/FormattingUtils.cs @@ -31,6 +31,8 @@ private FormattingUtils() { } + private static XPathExpression precedingSiblingsExpr = XPathExpression.Compile("preceding-sibling::*"); + /// /// Returns the full path to the context node. Clone the navigator to avoid loosing positioning. /// @@ -75,9 +77,8 @@ public static string GetFullNodePosition(XPathNavigator context, string previous } int sibs = 1; - - while (context.MoveToPrevious()) - if (context.Name == curr) sibs++; + foreach (XPathNavigator prev in context.Select(precedingSiblingsExpr)) + if (prev.Name == curr) sibs++; if (context.MoveToParent()) { diff --git a/src/Schematron/SyncEvaluationContext.cs b/src/Schematron/SyncEvaluationContext.cs index 4fb6100..d2d140f 100644 --- a/src/Schematron/SyncEvaluationContext.cs +++ b/src/Schematron/SyncEvaluationContext.cs @@ -147,7 +147,7 @@ private bool Evaluate(Pattern pattern, StringBuilder output) /// different methods for accessing the underlying source. /// /// This makes the implementation both performant and compliant with - /// the restriction about node mathing (see ) in the spec. + /// the restriction about node matching (see ) in the spec. /// /// ///