Page 1 of 1

Adding elements to merged XML document

Posted: Tue Jun 06, 2017 7:49 pm
by molloy84
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.

Re: Adding elements to merged XML document

Posted: Wed Jun 07, 2017 4:54 pm
by adrian
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