I have a large XML file and need to change certain values to those in another XML document based on multiple matching criteria.
My large XML file \'file1.xml\' is in the
The main thing to note is XML (and XSLT) is case-sensitive, and so a template that contains Student
in the path is not going to match a student
element in your XML.
Another issue is that you have missed out elements from the path, for example StudentOnModule
is the parent of MODOUT
, not instance.
Try this template....
<xsl:template match="student/instance[OWNINST = document('file2.xml')/studentstoamend/student/OWNINST]/StudentOnModule/MODOUT">
<xsl:copy-of select="document('file2.xml')/studentstoamend/student[OWNINST = current()/../../OWNINST][MODID = current()/../MODID]/MODOUT"/>
</xsl:template>
Note, I might be tempted to simplify the template, to avoid having to reference the second file twice....
<xsl:template match="MODOUT">
<xsl:variable name="modout" select="document('file2.xml')/studentstoamend/student[OWNINST = current()/../../OWNINST][MODID = current()/../MODID]/MODOUT" />
<xsl:choose>
<xsl:when test="$modout">
<xsl:copy-of select="$modout" />
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>