创建多个XML文件&XSLT的文件夹 [英] Creating multiple XML files & folders with XSLT
问题描述
我正在尝试创建样式表以将XML转换为XML的其他格式,并且在此过程中,它应该创建放置在单独文件夹中的多个XML文件.我要使用的XML文件很大(〜50000行),我想使其自动化.因此,我不必对每个部分进行硬编码.例如,如果我有一个像下面这样的简单XML:
I am trying to create an stylesheet to transform an XML to other format of an XML and in the process it should create multiple XML files that are placed in separate folders. The XML file I am trying to work with is very large(~50000 lines) and I want to automate it. So I don't have to hardcode every section. For example, if I have a simple XML like the following:
<Site>
<element run="test1">
<property name="aaa"/>
<property name="bbb"/>
<property name="ccc"/>
<element run="test2">
<property name="aaa"/>
<property name="bbb"/>
<property name="ccc"/>
<element run="test3">
<property name="aaa"/>
<property name="bbb"/>
<property name="ccc"/>
</element>
</element>
</element>
XSLT应该创建名为 test1
的文件夹,并将 test2
, test3
作为子文件夹( test1/test2/test3
)的XML,该XML由同一文件夹中的子节点 property
组成.因此,每个文件夹中都应包含小的XML.
XSLT should create folder named test1
and have test2
, test3
as subfolders (test1/test2/test3
) with an XML that consists of the child nodes property
in the same folder. So each folder should have small XML in it.
推荐答案
尝试以下方法:
<xsl:template match="Site">
<xsl:apply-templates select="//element"/>
</xsl:template>
<xsl:template match="element">
<xsl:result-document href="{string-join(ancestor-or-self::element/@run, '/')}/properties.xml">
<root>
<xsl:copy-of select="property"/>
</root>
</xsl:result-document>
</xsl:template>
这篇关于创建多个XML文件&XSLT的文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!