Exclude specific child nodes when the data structure is unknown

EDIT - I figured out a solution to my problem and posted a Q & A here.

I'm looking for XML processing that conforms to the EAD standard of the Library of Congress (found here ). Unfortunately, the standard is very loose regarding the XML structure.

For example, a tag <bioghist>may exist in a tag <archdesc>or in a tag <descgrp>, or nested in another tag <bioghist>, or in combination with the above, or may be completely excluded. I found that it is very difficult to select only the bioghist tag that I am looking for without selecting others.

Below are a few of the various possible EAD XML documents that XSLT can handle:

First example

<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>

Second example

<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>

Third example

<ead>
<eadheader>
    <archdesc>
        <descgrp>
            <bioghist>one</bioghist>
        </descgrp>
        <dsc>
            <c01>
                <c02>
                    <bioghist>three</bioghist>
                </c02>
            </c01>
        </dsc>
    </archdesc>
</eadheader>
</ead>

, XML EAD <bioghist> . , , . EAD :

<records>
<primary_record>
    <biography_history>first</biography_history>
</primary_record>
<child_record>
    <biography_history>second</biography_history>
</child_record>
<granchild_record>
    <biography_history>third</biography_history>
</granchild_record>
</records>

<records>
<primary_record>
    <biography_history>first</biography_history>
</primary_record>
<child_record>
    <biography_history>second</biography_history>
</child_record>
<granchild_record>
    <biography_history>third</biography_history>
</granchild_record>
</records>

<records>
<primary_record>
    <biography_history>first</biography_history>
</primary_record>
<child_record>
    <biography_history></biography_history>
</child_record>
<granchild_record>
    <biography_history>third</biography_history>
</granchild_record>
</records>

"" <primary_record>, <xsl:apply-templates select="/ead/eadheader/archdesc/bioghist", <archdesc>. <descgrp> <bioghist> . select="//bioghist", <bioghist>. select="//bioghist[1]", <bioghist>, <c01>, "" .

, , <cxx>, . . node, (<c01> ) "RN", <xsl:apply-templates select=".//bioghist [name(..)=name($RN) or name(../..)=name($RN)]">. EAD, <bioghist> , , - EAD, -, ( EAD).

, -

  • <bioghist> - node,
  • , <c??>

, . , , - . , , . .

+5
2

Q & A, XML , , . , , .

0

, , .

:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:my="my:my" exclude-result-prefixes="my">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <my:names>
  <n>primary_record</n>
  <n>child_record</n>
  <n>grandchild_record</n>
 </my:names>

 <xsl:variable name="vNames" select="document('')/*/my:names/*"/>

 <xsl:template match="/">
  <xsl:apply-templates select=
   "//bioghist[following-sibling::node()[1]
                                [self::descgrp]
              ]"/>
 </xsl:template>

 <xsl:template match="bioghist">
  <xsl:variable name="vPos" select="position()"/>

  <xsl:element name="{$vNames[position() = $vPos]}">
   <xsl:value-of select="."/>
  </xsl:element>
 </xsl:template>

 <xsl:template match="text()"/>
</xsl:stylesheet>

XML-:

<ead>
    <eadheader>
        <archdesc>
            <bioghist>first</bioghist>
            <descgrp>
                <bioghist>first</bioghist>
                <bioghist>
                    <bioghist>first</bioghist></bioghist>
            </descgrp>
            <dsc>
                <c01>
                    <bioghist>second</bioghist>
                    <descgrp>
                        <bioghist>second</bioghist>
                        <bioghist>
                            <bioghist>second</bioghist></bioghist>
                    </descgrp>
                    <c02>
                        <bioghist>third</bioghist>
                        <descgrp>
                            <bioghist>third</bioghist>
                            <bioghist>
                                <bioghist>third</bioghist></bioghist>
                        </descgrp>
                    </c02>
                </c01>
            </dsc>
        </archdesc>
    </eadheader>
</ead>

:

<primary_record>first</primary_record>
<child_record>second</child_record>
<grandchild_record>third</grandchild_record>
+2

All Articles