zoukankan      html  css  js  c++  java
  • 利用xslt合并多个xml文件到一个文件

    直接上代码

    1.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <JobRecords>
        <JobRecord>
            <Brand>Corporate1</Brand>
            <WorkTypes>
                <WorkTypeRecord>
                    <Title>Permanent1</Title>
                </WorkTypeRecord>
            </WorkTypes>
        </JobRecord>
    </JobRecords>

    2.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <JobRecords>
        <JobRecord>
            <Brand>Corporate2</Brand>
            <WorkTypes>
                <WorkTypeRecord>
                    <Title>Permanent2</Title>
                </WorkTypeRecord>
            </WorkTypes>
        </JobRecord>
    </JobRecords>

    merge.xslt

    <?xml version="1.0" encoding="UTF-8" ?>
    
    <!-- New XSLT document created with EditiX XML Editor (http://www.editix.com) at Thu Nov 12 14:29:49 CST 2020 -->
    
    <xsl:stylesheet version="2.0" exclude-result-prefixes="xs xdt err fn" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:err="http://www.w3.org/2005/xqt-errors">
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/">
            <xsl:copy>
            <xsl:apply-templates mode="rootcopy"></xsl:apply-templates>
            </xsl:copy>
        </xsl:template>
        
        <xsl:template match="node()" mode="rootcopy">
    
            <xsl:copy>
    
                <xsl:variable name="folderURI" select="resolve-uri('.',base-uri())"/>
    
                <xsl:for-each select="collection(concat($folderURI, '?select=*.xml;recurse=yes'))/*/node()">
    
                    <xsl:apply-templates mode="copy" select="."/>
    
                </xsl:for-each>
    
            </xsl:copy>
    
        </xsl:template>
        
        <xsl:template match="node()|@*" mode="copy">
    
            <xsl:copy>
    
                <xsl:apply-templates mode="copy" select="@*"/>
    
                <xsl:apply-templates mode="copy"/>
    
            </xsl:copy>
    
        </xsl:template>
    
    
    
        <!-- Handle default matching -->
    
        <xsl:template match="*"/>
    </xsl:stylesheet>

    输出结果:

    <?xml version="1.0" encoding="UTF-8"?>
    <JobRecords>
        <JobRecord>
            <Brand>Corporate1</Brand>
            <WorkTypes>
                <WorkTypeRecord>
                    <Title>Permanent1</Title>
                </WorkTypeRecord>
            </WorkTypes>
        </JobRecord>
    
        <JobRecord>
            <Brand>Corporate2</Brand>
            <WorkTypes>
                <WorkTypeRecord>
                    <Title>Permanent2</Title>
                </WorkTypeRecord>
            </WorkTypes>
        </JobRecord>
    
    </JobRecords>
  • 相关阅读:
    react路由,路由配置写在哪里?
    fastadmin中自建留言板的总结(一)TP5.0的数据流程
    精通JS的调试之控制台api大全,抓住数据的本质,本质!本质!!
    react中的,invoke,evoke,dispatch,assign都是什么意思,有什么区别
    leetcode——215.数组中的第k个最大的数
    leetcode——53.最大子序和
    leetcode——441.排列硬币
    leetcode——1137.第N个斐波那契数
    leetcode——70.爬楼梯
    leetcode——509.斐波那契数
  • 原文地址:https://www.cnblogs.com/DomoYao/p/13964259.html
Copyright © 2011-2022 走看看