如何使用xsl拆分html文件?

时间:2011-11-28 07:32:52

标签: c# html xml xslt

我有一个xsl样式表,它将xml转换为html。有时候html文件对于大型xml文件来说变得非常庞大。我想修改样式表,如果在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">
&lt;!--
#foldheader{cursor:pointer;cursor:hand ; font-weight:bold ;
list-style-image:url(fold.gif)}
#foldinglist{list-style-image:url(list.gif)}
//--&gt;
            </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() &lt; 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: &quot;UNKNOWN&quot;, Dimse: C-STORE-RQ. Using Definitions with AE Name &quot;DICOM&quot; - AE Version &quot;3.0&quot;">
      <results>
        <id>76</id>
        <Resultfile>\TesEnv\MediaRes\Summary_000_20110922192249_216_data_dcm_DCM_res.xml</Resultfile>
      </results>
    </message>
    <message Name="File: &quot;\Datasets\20110922192249.216.data.dcm&quot; is not a valid DICOM Media Storage File. No &quot;DICM&quot; 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 &quot;\Datasets\20110922192249.216.data.dcm&quot; 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 个答案:

答案 0 :(得分:0)

在此处查看:http://msdn.microsoft.com/en-us/library/ms950784.aspx,了解有关从xsl转换生成多个输出的信息。

顺便说一句,你的xsl样式表难以阅读......你应该使用其他模板来解决错误与错误。警告而不是xsl:for-each。