0
我尝试使用标识转换来复制以下xml文件。 我想要做的是使用集合函数将所有源文件的所有内容合并到一个xml文件中。我还需要在所有元素上使用generate-id()。 我已阅读此论坛和其他地方,但由于我仍在使用我的XSLT,因此我很难获取所需的文档。使用一个XSLT转换多重XML文件
我已经看过几个例子,但是他们没有一个能够做我所需要的。
下面是我使用Saxon 9.4.0.6来尝试转换的样式表。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="node()|@*" mode="inFile">
<xsl:copy>
<xsl:apply-templates mode="inFile" select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:variable name="titles" select="collection('file:/c:/U/?select=*.dita;recurse=yes')//title"/>
<xsl:for-each select="$titles">
<xsl:copy-of select="."/>
</xsl:for-each>
<xsl:variable name="parags" select="collection('file:/c:/U/?select=*.dita;recurse=yes')//p"/>
<xsl:for-each select="$parags">
<xsl:copy-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
这里是样本源XML文档:
<?xml version="1.0" encoding="UTF-8"?>
<myparag audience="Test_Para" id="para_H56100">
<title id="title1">First</title>
<body>
<p>First paragraph for compilation.
</p>
</body>
</myparag>
<?xml version="1.0" encoding="UTF-8"?>
<myparag audience="Test_Para" id="para_H561002">
<title id="title2">Second</title>
<body>
<p><p>Second paragraph for compilation.
</p>
</body>
</myparag>
<?xml version="1.0" encoding="UTF-8"?>
<myparag audience="Test_Para id="para_H561009">
<title id="title3">Third</title>
<body>
<p><p>Third paragraph for compilation.
</p>
<p>See paragraph one.
</p>
</body>
</myparag>
这里是希望合并的XML文档
<?xml version="1.0" encoding="UTF-8"?>
<glossgroup audience="Test_Para" id="para_H561080">
<glossaryentry id="dd1">
<glossterm id="title1">First</glossterm>
<glossdef>
<p>First paragraph for compilation.</p>
</glossdef>
</glossaryentry>
<glossaryentry id="dd2">
<glossterm id="title1">Second</glossterm>
<glossdef>
<p>Second paragraph for compilation.</p>
</glossdef>
</glossaryentry>
<glossaryentry id="dd3">
<glossterm id="title1">Third</glossterm>
<glossdef>
<p>Third paragraph for compilation.</p>
<p>See detail about third paragraph.</p>
</glossdef>
</glossaryentry>
</glossgroup>
谢谢你纠正我提交XSLT很多纳文。它正在产生所需的结果。 – ManUO