Change values in XML based to those referenced in another XML file based on multiple match criteria

后端 未结 1 1185
予麋鹿
予麋鹿 2021-01-26 04:38

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

相关标签:
1条回答
  • 2021-01-26 05:09

    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>
    
    0 讨论(0)
提交回复
热议问题