Is it possible to only incorporate portions of an element added to XML via xinclude?

70 Views Asked by At

I have an XInclude I'm incorporating into my XML in order to not have to repeat content. This works great for most of my uses, but there's a specific case where the object is slightly different. There, the descriptive information (what is under the "p" tags under support in the layout below) is specific to the individual file I'm putting the XInclude in, but only one "p" tag would apply depending on the file. The XInclude I'm using is

<xi:include href="../Witness_Descriptions/Clopton_Chantry_Chapel.xml" xpointer="Clopton_Chantry_Chapel" xmlns:xi="http://www.w3.org/2001/XInclude"/>
        

And the section pulled from the Clopton_Chantry_Chapel.xml file is the following (with most content between element tags stripped for ease of understanding):

<sourceDesc xml:id="Clopton_Chantry_Chapel">
    <msDesc xml:id="Clopton">
        <msIdentifier/>
        <msContents/>
            <msItem n="Center Beam">
                <p/>
            </msItem>
            <msItem n="Crossbeams">
                <p/>
            </msItem>
            <msItem n="South Wall">
                <p/>
            </msItem>
            <msItem n="South Wall">
                <p/>
            </msItem>
            <msItem n="West Wall">
                <p/>
            </msItem>
            <msItem n="North Wall">
                <p/>
            </msItem>
            <msItem n="East Wall">
                <p/>
            </msItem>
        </msContents>
        <physDesc>
            <objectDesc>
                <supportDesc>
                    <support>
                        <material>wood</material>
                        <material>paint</material>
                        <p>The text of the "Testament" is composed on carved wooden panels intended to appear like
                            scrollwork wrapped around a typical vinework motif along the juncture between the roof and the four walls of the chapel. Each carved panel
                            was then painted to give the appearance of lined parchment.</p>
                       <p>Similarly, the text of the <emph rend="italic">Quis Dabit Meo Capiti Fontem
                            Lacrimarum</emph> is composed on badly damaged painted panels
                        intended to appear like scrollwork wrapped around a typical vinework
                        motif.</p>
                </support>
                    </support>
                </supportDesc>
                <layoutDesc>
                    <layout/>
                </layoutDesc>
            </objectDesc>
            <handDesc>
                <handNote scope="sole" script="textura quadrata">
                    <p n="hand_intro"/>
                    <p n="hand_otiose"/>
                </handNote>
            </handDesc>
            <decoDesc>
                <decoNote/>
            </decoDesc>
        </physDesc>
        <history>
            <p/>
        </history>
    </msDesc>
</sourceDesc>

My question is this: is there a way to either fold the specific information into the element I'm including or create some kind of case statement within the XInclude itself? It feels like there should be, but I know XML/XSLT/XPath doesn't really tend to like things that are similar to object-oriented programming and the more convoluted XPath-based options I see online don't seem to work with Saxon, which is my particular parser. So am I out of luck?

1

There are 1 best solutions below

0
Norm On

You could try sinclude my Saxon extension function that implements XInclude. The XInclude support in Saxon proper is actually provided by Xerces. One of the reasons that it has limited support for fragment identifier schemes is that it's working in a streaming mode, where my extension function (for better or worse) operates on the whole document in memory.

You can use XPath expressions to select arbitrary fragments of the included document.