Internal Test: Verifies the filtering of nested matches using RootLevelOnly and InnermostOnly options.

ID: 941

				
					using uCalcSoftware;

var uc = new uCalc();
var t = uc.NewTransformer();
var txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>";
t.Text = txt;

// Parent rule matches the <p> tag. Its local transformer then extracts the 'id' attribute.
var parentRule = t.Pattern("<p {etc}>");
parentRule.LocalTransformer.FromTo("id={@string:id}", "{id}");
t.Filter();

Console.WriteLine("--- All Matches (Parent and Child) ---");
Console.WriteLine(t.GetMatches(MatchesOption.All).Text);
Console.WriteLine("");

Console.WriteLine("--- RootLevelOnly (Parent Matches) ---");
Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text);
Console.WriteLine("");

Console.WriteLine("--- InnermostOnly (Child Matches) ---");
Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text);
				
			
--- All Matches (Parent and Child) ---
<p aa>
aa
<p bb>
bb
<p cc>
cc

--- RootLevelOnly (Parent Matches) ---
<p aa>
<p bb>
<p cc>

--- InnermostOnly (Child Matches) ---
aa
bb
cc
				
					#include <iostream>
#include "uCalc.h"

using namespace std;
using namespace uCalcSoftware;

int main() {
   uCalc uc;
   auto t = uc.NewTransformer();
   auto txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>";
   t.Text(txt);

   // Parent rule matches the <p> tag. Its local transformer then extracts the 'id' attribute.
   auto parentRule = t.Pattern("<p {etc}>");
   parentRule.LocalTransformer().FromTo("id={@string:id}", "{id}");
   t.Filter();

   cout << "--- All Matches (Parent and Child) ---" << endl;
   cout << t.GetMatches(MatchesOption::All).Text() << endl;
   cout << "" << endl;

   cout << "--- RootLevelOnly (Parent Matches) ---" << endl;
   cout << t.GetMatches(MatchesOption::RootLevelOnly).Text() << endl;
   cout << "" << endl;

   cout << "--- InnermostOnly (Child Matches) ---" << endl;
   cout << t.GetMatches(MatchesOption::InnermostOnly).Text() << endl;
}
				
			
--- All Matches (Parent and Child) ---
<p aa>
aa
<p bb>
bb
<p cc>
cc

--- RootLevelOnly (Parent Matches) ---
<p aa>
<p bb>
<p cc>

--- InnermostOnly (Child Matches) ---
aa
bb
cc
				
					Imports System
Imports uCalcSoftware
Public Module Program
   Public Sub Main()
      Dim uc As New uCalc()
      Dim t = uc.NewTransformer()
      Dim txt = "<p id='aa'>xyz</p><p id='bb'>Hello</p ><p id='cc'>World</p>"
      t.Text = txt
      
      '// Parent rule matches the <p> tag. Its local transformer then extracts the 'id' attribute.
      Dim parentRule = t.Pattern("<p {etc}>")
      parentRule.LocalTransformer.FromTo("id={@string:id}", "{id}")
      t.Filter()
      
      Console.WriteLine("--- All Matches (Parent and Child) ---")
      Console.WriteLine(t.GetMatches(MatchesOption.All).Text)
      Console.WriteLine("")
      
      Console.WriteLine("--- RootLevelOnly (Parent Matches) ---")
      Console.WriteLine(t.GetMatches(MatchesOption.RootLevelOnly).Text)
      Console.WriteLine("")
      
      Console.WriteLine("--- InnermostOnly (Child Matches) ---")
      Console.WriteLine(t.GetMatches(MatchesOption.InnermostOnly).Text)
   End Sub
End Module
				
			
--- All Matches (Parent and Child) ---
<p aa>
aa
<p bb>
bb
<p cc>
cc

--- RootLevelOnly (Parent Matches) ---
<p aa>
<p bb>
<p cc>

--- InnermostOnly (Child Matches) ---
aa
bb
cc