如何使用 xsl 拆分 html 文件?
Posted
技术标签:
【中文标题】如何使用 xsl 拆分 html 文件?【英文标题】:How to split html files using xsl? 【发布时间】:2012-01-07 17:23:55 【问题描述】:我有一个将 xml 转换为 html 的 xsl 样式表。对于大型 xml 文件,有时 html 文件会变得非常大。我想修改样式表,如果html file1中的行数增加,那么我必须创建一个新的html(比如file2),并且必须将file2的链接放在file1中并显示。
我的 xsl 是,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dimse="urn:schemas-dvtk:dimse" xmlns:activity="urn:schemas-dvtk:activity" xmlns:validation="urn:schemas-dvtk:validation" xmlns:media="urn:schemas-dvtk:media" xmlns:dul="urn:schemas-dvtk:dul" xmlns:results="urn:schemas-dvtk:results" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xsl:template match="collection">
<html>
<head>
<style>
<xsl:text disable-output-escaping="yes">
<!--
#foldheadercursor:pointer;cursor:hand ; font-weight:bold ;
list-style-image:url(fold.gif)
#foldinglistlist-style-image:url(list.gif)
//-->
</xsl:text>
</style>
<script src="script.js"/>
</head>
<body>
<font size="-2" face="helvetica">
<script src="script.js"/>
<ul>
<xsl:for-each select="Error">
<li id="foldheader">Error</li>
<ul id="foldinglist" style="display:none">
<xsl:variable name="cur" select="0" />
<xsl:for-each select="message">
<li id="foldheader">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="results/id"/> * <xsl:value-of select="results/Resultfile"/> FOLDERLINK
</xsl:attribute>
<xsl:value-of select="@Name"/>
</xsl:element>
</li>
<ul id="foldinglist" style="display:none">
<xsl:for-each select="results">
<xsl:if test="position() < 2">
<li>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="id"/> * <xsl:value-of select="Resultfile"/>
</xsl:attribute>
<xsl:value-of select="Resultfile"/>
</xsl:element>
</li>
</xsl:if>
</xsl:for-each>
</ul>
</xsl:for-each>
</ul>
</xsl:for-each>
<xsl:for-each select="Warning">
<li id="foldheader">Warning</li>
<ul id="foldinglist" style="display:none">
<xsl:for-each select="message">
<li id="foldheader">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="results/id"/> * <xsl:value-of select="results/Resultfile"/> FOLDERLINK
</xsl:attribute>
<xsl:value-of select="@Name"/>
</xsl:element>
</li>
<ul id="foldinglist" style="display:none">
<xsl:for-each select="results">
<li>
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="id"/> * <xsl:value-of select="Resultfile"/>
</xsl:attribute>
<xsl:value-of select="Resultfile"/>
</xsl:element>
</li>
</xsl:for-each>
</ul>
</xsl:for-each>
</ul>
</xsl:for-each>
</ul>
</font>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
我的示例文档是,
<?xml version="1.0" encoding="utf-8"?>
<collection xmlns:dimse="urn:schemas-dvtk:dimse" xmlns:activity="urn:schemas-dvtk:activity" xmlns:validation="urn:schemas-dvtk:validation" xmlns:media="urn:schemas-dvtk:media" xmlns:dul="urn:schemas-dvtk:dul" xmlns:results="urn:schemas-dvtk:results" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Error>
<message Name="Type 2 attribute (0008,0090) should be present with at least a zero-length">
<results>
<id>58</id>
<Resultfile>\TesEnv\MediaRes\Summary_000_02167DCM_dcm_DCM_res.xml</Resultfile>
</results>
<results>
<id>36</id>
<Resultfile>\TesEnv\MediaRes\Summary_000_AA_dcm_DCM_res.xml</Resultfile>
</results>
</message>
</Error>Selected Dataset definition: "File Meta". Using AE Name "DICOM" - AE Version "3.0"51\TesEnv\MediaRes\Summary_000_02167DCM_dcm_DCM_res.xmlSelected Dataset definition: "Secondary Capture Image Storage SOP Class". Using AE Name "DICOM" - AE Version "3.0"52\TesEnv\MediaRes\Summary_000_02167DCM_dcm_DCM_res.xmlSelected Dataset definition: "File Meta". Using AE Name "DICOM" - AE Version "3.0"29\TesEnv\MediaRes\Summary_000_AA_dcm_DCM_res.xmlSelected Dataset definition: "Secondary Capture Image Storage SOP Class". Using AE Name "DICOM" - AE Version "3.0"30\TesEnv\MediaRes\Summary_000_AA_dcm_DCM_res.xml<Warning>
<message Name="Could not find Dataset definition for SOP UID: "UNKNOWN", Dimse: C-STORE-RQ. Using Definitions with AE Name "DICOM" - AE Version "3.0"">
<results>
<id>76</id>
<Resultfile>\TesEnv\MediaRes\Summary_000_20110922192249_216_data_dcm_DCM_res.xml</Resultfile>
</results>
</message>
<message Name="File: "\Datasets\20110922192249.216.data.dcm" is not a valid DICOM Media Storage File. No "DICM" FMI Prefix at offset 128.">
<results>
<id>A1</id>
<Resultfile>\TesEnv\MediaRes\Summary_000_20110922192249_216_data_dcm_DCM_res.xml</Resultfile>
</results>
</message>
<message Name="The file "\Datasets\20110922192249.216.data.dcm" does not have (valid) File Meta Information">
<results>
<id>75</id>
<Resultfile>\TesEnv\MediaRes\Summary_000_20110922192249_216_data_dcm_DCM_res.xml</Resultfile>
</results>
</message>
</Warning>\TesEnv\TesEnv\media.pdvt.xml<Directory>\TesEnv</Directory><FileName>\TesEnv\media.pdvt.xml</FileName>
</collection>
请给出一些拆分html文件的想法..
【问题讨论】:
【参考方案1】:查看此处:http://msdn.microsoft.com/en-us/library/ms950784.aspx,了解有关从 xsl 转换生成多个输出的信息。
顺便说一句,您的 xsl 样式表很难阅读...您应该为错误和警告使用额外的模板,而不是 xsl:for-each。
【讨论】:
感谢您的回复。错误和警告未修复。甚至错误的数量也会更多..所以我想将错误也拆分到多个文件中....同样的警告情况..以上是关于如何使用 xsl 拆分 html 文件?的主要内容,如果未能解决你的问题,请参考以下文章