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

五迷三道 提交于 2019-12-02 11:35:33

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>
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!