本文介绍了使用 XSLT 合并 html 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将多个 html 文件转换为一个文件意味着一本书中有多个章节.为此,我正在接收文本文件,其中文件列表的序列在哪里.在转换时,我没有得到正确的章节顺序:
I am transforming multiple html files to one file mean multiple chapters in a book. For that i am recieving text file where is the sequence of file list. While transforming i am not getting the proper sequences of the chapters:
TXT 文件:
FilePath=d:\Amrendra\edgar xml-html\All\Edger_Final\xml\07_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\02_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\03_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\04_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\05_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\06_Document_Edgar17Nov.out.indd,d:\Amrendra\edgar xml-html\All\Edger_Final\xml\01_FrontMatter_Edgar17Nov.out.indd
用于合并的 XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0">
<xsl:character-map name="m1">
<xsl:output-character character="•" string="&bull;"/>
<xsl:output-character character=" " string="&nbsp;"/>
<xsl:output-character character="’" string="&rsquo;"/>
</xsl:character-map>
<xsl:output method="xhtml" use-character-maps="m1"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:variable name="filelist">
<xsl:analyze-string select="unparsed-text('../book_bulidIndesign.txt')" regex="FilePath=(.*)">
<xsl:matching-substring>
<xsl:value-of select="normalize-space(regex-group(1))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="file-seq">
<map>
<xsl:for-each select="tokenize($filelist, ',')">
<file>
<xsl:attribute name="pos" select="position()"/>
<xsl:value-of select="iri-to-uri(concat('file:///', replace(replace(replace(., '\\InDesign\\', '\\XML\\'), 'indd$', 'html'), '\\', '/')))"/>
</file>
</xsl:for-each>
</map>
</xsl:variable>
<xsl:template match="/">
<html>
<body style="font: 10pt Times New Roman, Times, Serif">
<xsl:for-each select="document($file-seq/map/file)">
<xsl:apply-templates select="/node()/body/node()"/>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
注意:如果我尝试打印章节映射,它运行良好!所有 html 文件都在特定路径下可用.
NOTE : If i am try to print the mapping of chapters its working well! All html files are available on the specific path.
推荐答案
感谢每个人的建议,我按照顺序将文档存储在变量中,然后应用这些方式链接:
Thanks Every one for the suggestions i did this in storing the documents inside the variable as per the order and after apply these way link:
<xsl:variable name="filelist">
<xsl:analyze-string select="unparsed-text('../book_bulidIndesign.txt')" regex="FilePath=(.*)">
<xsl:matching-substring>
<xsl:value-of select="normalize-space(regex-group(1))"/>
</xsl:matching-substring>
</xsl:analyze-string>
</xsl:variable>
<xsl:variable name="all-chapter">
<xsl:for-each select="tokenize($filelist, ',')">
<xsl:variable name="c_path">
<xsl:value-of select="concat('file:///', iri-to-uri(replace(replace(replace(., '\\InDesign\\', '\\XML\\'), 'indd$', 'html'), '\\', '/')))"/>
</xsl:variable>
<xsl:copy-of select="document($c_path)"/>
</xsl:for-each>
</xsl:variable>
<xsl:template match="/">
<html>
<body style="font: 10pt Times New Roman, Times, Serif">
<xsl:apply-templates select="$all-chapter/node()/body/node()"/>
<!--<xsl:apply-templates select="$all-chapter/node()"/>-->
</body>
</html>
</xsl:template>
这篇关于使用 XSLT 合并 html 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!