Adding elements to merged XML document

Here should go questions about transforming XML with XSLT and FOP.
molloy84
Posts: 1

Adding elements to merged XML document

Tue Jun 06, 2017 7:49 pm

I am new to XML/XSL and have a question regarding adding elements to merged XML files. I have managed to merge 400+ XML files, but cannot figure out how to batch add an element to each. I hope this makes sense. I am working with the MODS schema and need to add the <mods:note type="ownership"> element to each record.
adrian
Posts: 2326

Re: Adding elements to merged XML document

Wed Jun 07, 2017 4:54 pm

Hi,

How did you merge the 400 XML files, did you use an XSL stylesheet or a plain text merge and some manual fixing?

If you use a copy stylesheet, you should be able to create an xsl:template for the parent element in which you want to add that new element.
e.g.

Code: Select all

    <!-- Match document -->
    <xsl:template match="/">
        <xsl:apply-templates mode="copy" select="."/>
    </xsl:template>
    <!-- Deep copy template -->
    <xsl:template match="*|text()|@*" mode="copy">
        <xsl:copy>
            <xsl:apply-templates mode="copy" select="@*"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>
     <xsl:template match="*:myparent" mode="copy">
        <xsl:copy>
            <xsl:apply-templates mode="copy" select="@*"/>
            <mods:note type="ownership"/>
            <xsl:apply-templates mode="copy"/>
        </xsl:copy>
    </xsl:template>
   

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “XSLT and FOP”

Who is online

Users browsing this forum: No registered users and 0 guests