[英]Merging of multiple xml files to a single xml file using xslt 2.0 - worked. Having trouble doing the same transformation using xslt 1.0
我在一個文件夾中有多個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進行相同的轉換。 但是我在收藏時出錯。 我該如何實現? 任何建議,將不勝感激。 謝謝。
在XSLT 1.0中處理多個XML文件的唯一方法是使用document
函數,其中一個參數是XML文檔,該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外部目錄(結構)中要處理的所有文件來創建該特定文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.