0

是否可以通过 XSLT 转换将输入 Xmls 上的数组转换为单个 Xml?
目前我正在使用以下代码,这非常简单。

一个 Xml -> 一个 XSLT -> 一个输出 Xml

代码

def w = new StringWriter()
TransformerFactory.newInstance()
                  .newTransformer( new StreamSource( new StringReader( xslt ) ) )
                  .transform( new StreamSource( new StringReader( xmlAsString ) ),
                              new StreamResult( w ) )
4

1 回答 1

0

The concept is that you have one input file, one transformation file and one output file. I think you cannot do a XSLT transformation with more than one input file (you could merge them before but this is not very elegant).

However you can access as many documents in your XSLT Stylesheet as you want by using the document function. I would do it like that: Define an input file that includes all the documents you want to access e.g.

<files>
   <file>
     <path>File1.xml</path>
   </file>

   <file>
     <path>File2.xml</path>
   </file>
</files>

Take this file as an input file and use the document function to access them:

<xsl:template match = "file">
    <xsl:copy-of select="document(./path)/..."/>
</xsl:template>

With the document function, you can access all input files and apply transformations to the nodes specified there. So you can handle an arbitrary number of input files.

于 2013-09-23T14:12:48.087 回答