我在一个文件夹中有多个xml源文件。通过使用下面的xslt,我能够将所有的xml文件组合成一个xml文件。此转换使用2.0中提供的“集合”。
<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进行同样的转换。但我在收集时遇到错误。我该如何实现这一点?如有任何建议,我们将不胜感激。谢谢。
发布于 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之外的目录(结构)中。
https://stackoverflow.com/questions/42812603
复制相似问题