提问人:Kita Ansari 提问时间:8/17/2023 最后编辑:Martin HonnenKita Ansari 更新时间:8/18/2023 访问量:37
注释 <xref> 标签,如果 section/@id 与文件夹 XML 或文件夹 XML 文件外部不匹配,则将文本保持为纯文本
comment the <xref> tag and keep the text as plain, if section/@id is not matched with in folder xml or outside folder xml file
问:
如果在同一文件夹 xml 文件或其他文件夹 xml 文件中不匹配,我们要注释标记:<xref>
section/@id
每个文件夹都有多个/单个 xml 文件,并且标记将位于所有 xml 文件中<xref>
section/@id
- 此标记在文件夹中,但文件夹中的部分,如果两者都匹配,则保持值标记不匹配,则不匹配,然后注释标记,使文本保持纯文本。
<xref href="aag-dep1_1.01">some text here</xref>
"aat-fti"
eat-rw
xref/@href
section/@id
xref
xref
请帮助和建议,谢谢
在屏幕截图中查看下面的文件夹结构,每个文件夹都有xml文件,但文档中带有任何xml文件:xref/@href
sectin/@id
在 aa-fti
文件夹中输入带有 section/@id
的 xml
<?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>
在 eat-rw
文件夹中输入带有外部参照/@href
的 xml 文件
<?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>
答:
1赞
Martin Honnen
8/18/2023
#1
将 XSLT 3 与 Saxon 9.9 一起使用,如果将以下 XSLT 放在已显示的所有子文件夹的父文件夹中,它会递归处理所有文件并将转换后的结果写入例如:*.xml
subfoldername-output
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="3.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="#all"
expand-text="yes">
<xsl:param name="collection-uri" select="'?select=*.xml;recurse=yes'"/>
<xsl:param name="collection-docs" select="collection($collection-uri)"/>
<xsl:key name="section" match="section" use="@id"/>
<xsl:mode on-no-match="shallow-copy"/>
<xsl:template name="xsl:initial-template">
<xsl:apply-templates select="$collection-docs"/>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="result-uri" select="let $uri-tokens := tokenize(base-uri(), '/') return string-join(($uri-tokens[position() lt last() - 1], $uri-tokens[last() - 1] || '-output', $uri-tokens[last()]), '/')"/>
<xsl:result-document href="{$result-uri}">
<xsl:apply-templates/>
</xsl:result-document>
</xsl:template>
<xsl:template match="xref[not(some $doc in $collection-docs satisfies key('section', @href, $doc))]">
<xsl:comment><xref href="<xsl:value-of select="@href"/>"></xsl:comment><xsl:apply-templates/><xsl:comment></xref></xsl:comment>
</xsl:template>
</xsl:stylesheet>
使用初始模板开始处理,不使用输入文件。我认为该方法应该适用于简单的文件夹结构(例如,带有 XSLT 的父文件夹包含一个级别的不同子文件夹,其中包含要处理的 XML 文档),但请确保在一些测试示例数据上仔细测试它,然后再将其用于整个文件夹集。
评论
0赞
Kita Ansari
8/18/2023
谢谢@Martin,我会尝试使用 xslt 2.0 吗?
0赞
Martin Honnen
8/18/2023
Saxon 9.9 是 XSLT 3 处理器,因此我建议在 XSLT 代码中使用。version="3.0"
0赞
Kita Ansari
8/18/2023
好的,我会尽量让你知道的
0赞
Kita Ansari
8/18/2023
非常感谢@Martin,它工作正常
评论