XSL 2.0在保留文件夹结构的同时转换XML文件 [英] XSL 2.0 Transform XML files while preserving folder structure

查看:107
本文介绍了XSL 2.0在保留文件夹结构的同时转换XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下XSL将一堆XML文件从一种格式转换为另一种格式. 转换工作正常,尽管到目前为止我还没有解决两个问题:

I have the following XSL to transform a bunch of XML files from one format to another. The transformation is working fine though I have two issues unresolved so far:

1)首先,在转换文件时,我需要调整样式表中的参数,使其仅定位名称长度超过7个字符的文件;

1) First when transforming the files I need to adjust my parameter in the style sheet to target only files that have names longer than 7 characters;

2)其次,我需要能够在保留源文件的文件夹结构的同时转换所有文件.我想知道是否有办法保留源文件夹中相同的文件夹结构. 所有文件都位于基于字母命名的文件夹中,例如:A,B,C,D,F....因此,我需要转换文件夹A中的所有文件,并将它们放在名为A的新文件夹中.也按字母顺序命名.

2) Secondly, I need to be able to transform all the files while preserving the folder structure of the source files. I was wondering if there is way to preserve the same folder structure like from the source folder. All the files are located in folders named based on the alphabet like : A, B, C, D, F .... So I need to transform all files in folder A and put them in a new folder named A. The files are also named by alphabetical order.

这是我的样式表:

<?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) &gt; 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>

谢谢.

推荐答案

(a)select = *.dita实际上是伪装成glob的正则表达式,您应该可以使用select=[A-Za-z0-9]{7,}.dita之类的东西更具选择性.

(a) the select=*.dita is actually a regular expression masquerading as a glob, and you should be able to use something like select=[A-Za-z0-9]{7,}.dita to be more selective.

(b)应用于文件的函数document-uri()返回输入文件的URI(如果已知),并且由此您应该能够构造require输出文件名.

(b) the function document-uri() applied to a file returns the URI of the input file if known, and from this you should be able to construct the require output file name.

这篇关于XSL 2.0在保留文件夹结构的同时转换XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆