We want to comment the <xref> tags if section/@id is not matched in the same folder xml files or other folder xml files:
Each folder have multiple/single xml files and <xref> and section/@id tags will be in the all xml files
- This
<xref href="aag-dep1_1.01">some text here</xref>tag in the"aat-fti"folder but section in theeat-rwfolder, if matched bothxref/@hrefandsection/@idthen keep valuexreftag as it is, it not matched then comment thexreftags keep the text as plain.
Please help and suggest, Thanks
See the below folder structure in screenshot, each folder have xml files but xref/@href and sectin/@id any xml files pr with in documents:

Input xml with section/@id in the aa-fti folder
<?xml version="1.0" encoding="UTF-8"?>
<book id="book_id">
<title>Generally Accepted Accounting Principles</title>
<chapter id="chapter_id" role="ls_level_2">
<chapterinfo>
<titleabbrev>Chapter_abb</titleabbrev>
<title>Chapter_title</title>
</chapterinfo>
<section id="aag-dep1_01">
<para>text here</para>
<para>text here</para>
<para>containing auditing <xref href="fir_56_10">some text here</xref> guidance related to generally accepted auditing standard</para>
<para> the effective dates for FASB ASU No. 2018 <xref href="aag-dep1_1.01">some text here</xref></para>
<section id="aag-dep1_1.01">
<para>text here <xref href="fot_79_ut">some text here</xref></para>
<para>text here</para>
<para>text here<xref href="aag-dep1_01">some text here</xref></para>
</section>
<section id="aag-dep1_2.01">
<para>text here</para>
<para>text here</para>
<para>text here <xref href="aag-dep1_02">some text here</xref></para>
</section>
</section>
<section id="aag-dep1_02">
<para>text here</para>
<para>text here</para>
<para>ces, including engagements for entities in specia</para>
<para>example, a large calendar-year public insurance en</para>
<section id="aag-dep1_1.02">
<para>text here</para>
<para>text here</para>
<para>text here <xref href="tih52_23">some text here</xref></para>
</section>
</section>
<section id="aag-dep1_regulation_and_oversight">
<para>text <xref href="aag-dep1_1.02">some text here</xref> here</para>
<para>text here</para>
<para>early application may do so as of the beginning</para>
<para>Other auditing publications have no authoritative status;</para>
<section id="aag-dep1_08">
<para>text here <xref href="aag-dep1_regulation_and_oversight">some text here</xref></para>
<para>text <xref href="nov1_22">some text here</xref> here</para>
<para>text here</para>
</section>
</section>
</chapter>
</book>
Input xml file with xref/@href in the eat-rw folder
<?xml version="1.0" encoding="UTF-8"?>
<book id="book_id">
<title>Generally Accepted Accounting Principles</title>
<chapter id="chapter_id" role="ls_level_2">
<chapterinfo>
<titleabbrev>Chapter_abb</titleabbrev>
<title>Chapter_title</title>
</chapterinfo>
<section id="aag-dep1_01">
<para>text here</para>
<para>text here</para>
<para>containing auditing <!--<xref href="fir_56_10">-->some text here<!--</xref>--> guidance related to generally accepted auditing standard</para>
<para> the effective dates for FASB ASU No. 2018 <xref href="aag-dep1_1.01">some text here</xref></para>
<section id="aag-dep1_1.01">
<para>text <!--<xref href="fot_79_ut">-->some text here<!--</xref>--> here</para>
<para>text here</para>
<para>text here<xref href="aag-dep1_01">some text here</xref></para>
</section>
<section id="aag-dep1_2.01">
<para>text here</para>
<para>text here</para>
<para>text here <xref href="aag-dep1_02">some text here</xref></para>
</section>
</section>
<section id="aag-dep1_02">
<para>text here</para>
<para>text here</para>
<para>ces, including engagements for entities in specia</para>
<para>example, a large calendar-year public insurance en</para>
<section id="aag-dep1_1.02">
<para>text here</para>
<para>text here</para>
<para>text here <!--<xref href="tih52_23">-->some text here<!--</xref>--></para>
</section>
</section>
<section id="aag-dep1_regulation_and_oversight">
<para>text <xref href="aag-dep1_1.02">some text here</xref> here</para>
<para>text here</para>
<para>early application may do so as of the beginning</para>
<para>Other auditing publications have no authoritative status;</para>
<section id="aag-dep1_08">
<para>text here <xref href="aag-dep1_regulation_and_oversight">some text here</xref></para>
<para>text <!--<xref href="nov1_22">-->some text here<!--</xref>--> here</para>
<para>text here</para>
</section>
</section>
</chapter>
</book>
Using XSLT 3 with Saxon 9.9, if you put the following XSLT in the parent folder of all the subfolders you have shown, it processes all
*.xmlfiles recursively and writes the transformed result to e.g.subfoldername-output:Start the processing with the initial template and no input file. I think the approach should work with a simple folder structure (e.g. the parent folder with the XSLT contains one level of different subfolders with XML documents to be processed) but make sure you test that carefully on some test sample data before using it on your full folder set.