Adding elements to merged XML document

Here should go questions about transforming XML with XSLT and FOP.
molloy84
Posts: 1
Joined: Mon Jun 05, 2017 7:30 pm

Adding elements to merged XML document

Post 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.
adrian
Posts: 2855
Joined: Tue May 17, 2005 4:01 pm

Re: Adding elements to merged XML document

Post 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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply