小编aar*_*dev的帖子

数据结构未知时排除某些子节点

编辑 - 我已经找到解决问题的方法,并在此处发布了问答.

我正在寻找符合美国国会图书馆EAD标准的XML(在此处找到).不幸的是,关于XML的结构,标准非常宽松.

例如,<bioghist>标签可以存在于<archdesc>标签内,或<descgrp>标签内,或嵌套在另一个<bioghist>标签内,或上述的组合中,或者可以完全省略.我发现很难选择我正在寻找的bioghist标签而不选择其他标签.

以下是我的XSLT可能必须处理的一些不同的可能的EAD XML文档:

第一个例子

<ead>
<eadheader>
    <archdesc>
        <bioghist>one</bioghist>
        <dsc>
            <c01>
                <descgrp>
                    <bioghist>two</bioghist>
                </descgrp>
                <c02>
                    <descgrp>
                        <bioghist>
                            <bioghist>three</bioghist>
                        </bioghist>
                    </descgrp>
                </c02>
            </c01>
        </dsc>
    </archdesc>
</eadheader>
</ead>
Run Code Online (Sandbox Code Playgroud)

第二个例子

<ead>
<eadheader>
    <archdesc>
        <descgrp>
            <bioghist>
                <bioghist>one</bioghist>
            </bioghist>
        </descgrp>
        <dsc>
            <c01>
                <c02>
                    <descgrp>
                        <bioghist>three</bioghist>
                    </descgrp>
                </c02>
                <bioghist>two</bioghist>
            </c01>
        </dsc>
    </archdesc>
</eadheader>
</ead>
Run Code Online (Sandbox Code Playgroud)

第三个例子

<ead>
<eadheader>
    <archdesc>
        <descgrp>
            <bioghist>one</bioghist>
        </descgrp>
        <dsc>
            <c01>
                <c02>
                    <bioghist>three</bioghist>
                </c02>
            </c01>
        </dsc>
    </archdesc>
</eadheader>
</ead> …
Run Code Online (Sandbox Code Playgroud)

xslt xpath xml-parsing

5
推荐指数
1
解决办法
394
查看次数

标签 统计

xml-parsing ×1

xpath ×1

xslt ×1