首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用xslt 2.0将多个xml文件合并到单个xml文件中-很有效。在使用xslt 1.0执行相同的转换时遇到困难

使用xslt 2.0将多个xml文件合并到单个xml文件中-很有效。在使用xslt 1.0执行相同的转换时遇到困难
EN

Stack Overflow用户
提问于 2017-03-15 22:27:24
回答 1查看 1.2K关注 0票数 0

我在一个文件夹中有多个xml源文件。通过使用下面的xslt,我能够将所有的xml文件组合成一个xml文件。此转换使用2.0中提供的“集合”。

代码语言:javascript
复制
<xsl:stylesheet version="2.0" 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">
    <xsl:output method="xml"/>
    <xsl:param name="inputFolder">file:\C:\Desktop\RD\XSLTransformationTest\SourceXML</xsl:param> 

    <xsl:template match="/">        
        <xsl:variable name="filename" select="translate(concat($inputFolder, '\SingleSource.XML'),'\','/')"/>
        <xsl:message><xsl:value-of select="$filename"/></xsl:message>
        <xsl:result-document method="xml" href="{$filename}">
        <xsl:copy>
            <xsl:apply-templates mode="rootcopy"/>
        </xsl:copy>
        </xsl:result-document>
    </xsl:template>

    <xsl:template match="node()" mode="rootcopy">
        <xsl:copy>              
            <xsl:variable name="folderURI"  select="$inputFolder"/>     
            <xsl:message><xsl:value-of select="$folderURI"/></xsl:message>           
            <xsl:for-each select="collection(translate(concat($folderURI, '?select=*.xml;recurse=yes'),'\','/'))/*/node()">
                <xsl:apply-templates mode="copy" select="."/>
            </xsl:for-each>           
        </xsl:copy>
    </xsl:template>

    <!-- Deep copy 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>

现在,我正尝试使用xslt 1.0进行同样的转换。但我在收集时遇到错误。我该如何实现这一点?如有任何建议,我们将不胜感激。谢谢。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-03-15 23:11:25

在XSLT1.0中,处理多个XML文件的惟一方法是使用document函数,该函数的参数是列出您想要处理的文档的XML文档,例如<xsl:copy-of select="document(document('doc-list.xml')//file/@src)/*/node()"/>,如果文件doc-list.xml具有<files><file src="file1.xml"/><file src="file2.xml"/></files>。您需要创建该特定文件,所有要处理的文件都在XSLT之外的目录(结构)中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42812603

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档