我有以下 XSL 将一堆 XML 文件从一种格式转换为另一种格式。尽管到目前为止我有两个问题尚未解决,但转换工作正常:
1)首先在转换文件时,我需要调整样式表中的参数以仅针对名称超过 7 个字符的文件;
2)其次,我需要能够在保留源文件的文件夹结构的同时转换所有文件。我想知道是否有办法保留与源文件夹相同的文件夹结构。所有文件都位于基于字母命名的文件夹中,例如:A、B、C、D、F .... 所以我需要转换文件夹 A 中的所有文件并将它们放在一个名为 A 的新文件夹中。文件是也按字母顺序命名。
这是我的样式表:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"
xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/">
<!-- This adds DOCTYPE declaration -->
<xsl:output method="xml" doctype-public="-//OASIS//DTD DITA Glossary//EN"
doctype-system="glossary.dtd" omit-xml-declaration="no" indent="yes"/>
<!-- The below line ensures that all empty space and carriage returns are removed from the title element producing proper file names -->
<xsl:strip-space elements="title"/>
<xsl:param name="files" select="collection('../DITA/B/?select=*.dita;recurse=yes')"/>
<!-- <xsl:variable name="filename" select="concat($files,position(),'topic')" />-->
<xsl:template match="node()">
<xsl:copy copy-namespaces="no">
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/">
<xsl:for-each select="$files//topic">
<xsl:if test="string-length(files) > 10">
<!-- not working, the purpose is to drop all the files whose name length is less than two letters -->
<xsl:value-of select="text()" disable-output-escaping="yes"/>
</xsl:if>
<xsl:result-document href="outputDITANEW/B/{title/text()|title/b/text()}.dita">
<glossentry id="{concat('test', generate-id())}">
<glossterm id="{concat('test_title', generate-id())}">
<xsl:value-of select="title"/>
</glossterm>
<glossdef>
<xsl:for-each select="body">
<xsl:apply-templates/>
</xsl:for-each>
</glossdef>
</glossentry>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
谢谢。