代码之家  ›  专栏  ›  技术社区  ›  shorif2000

如何删除transformiix:导致firefox

  •  0
  • shorif2000  · 技术社区  · 7 年前

    transformiix:result

    我怎样才能在firefox中删除它。它正在影响我的javascript。我试着在周围工作,但它不再工作了

    解决方法

    if($('body').length == 0){ // firefox is transforming xsl differently so this fix is needed
            var head = $("#top_section")
            var $set = $( document ).children();
            $set = $set.children();
            for(var i=1, len = $set.length; i < len; i +=5){
                $set.slice(i, i+6).wrapAll('<body />');
            }
        }
    

    使现代化

    xml

    <?xml version="1.0" encoding="UTF-8"?>
    <?xml-stylesheet type="text/xsl" href="/xslt/user_services_owners.xsl"?>
    <response>
      <header>
        <error>false</error>
        <message>success</message>
        <api_status>1</api_status>
        <api_response>success</api_response>
        <http_status>200</http_status>
        <http_response>ok</http_response>
        <format>xml</format>
        <csrf>946dc689cae6c5d0ae3fcf01de951493</csrf>
        <token>946dc689cae6c5d0ae3fcf01de951493</token>
        <user>UddinS2</user>
        <title>Manage Service, Project, Programme</title>
        <description>List, add, edit, and remove services, projects and programmes</description>
        <nav>
          <container>
            <title>Users</title>
            <link>#</link>
            <theme>#007c92</theme>
            <sub_modules>
              <title>Getting Started</title>
              <link>#</link>
              <theme>#007c92</theme>
              <menuitem>
                <title>File - CM Template v6.3</title>
                <link>/library/templates/FW-LB-CommsMatrix-Template-v6.3.xls</link>
              </menuitem>
              <menuitem>
                <title>Sudo Group Access</title>
                <link>/sudo_group_access.php?csrf=946dc689cae6c5d0ae3fcf01de951493</link>
              </menuitem>
            </sub_modules>
          </container>
        </nav>
        <server>1</server>
        <version>5.1</version>
      </header>
      <body>
        <recordset>
          <record>
            <ID>121</ID>
            <SERVICE_ID>201</SERVICE_ID>
            <NAME>UddinS2</NAME>
            <TYPE>owner</TYPE>
            <SERVICE>* Ad-hoc Submission</SERVICE>
          </record>
          <metadata>
            <num_rows>1</num_rows>
          </metadata>
        </recordset>
      </body>
    </response>
    

    /xslt/user\u services\u owners.xsl

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:import href="header.xsl" />
    
        <!-- <xsl:output method="html" encoding="UTF-8" omit-xml-declaration="yes"  indent="no" media-type="text/html" />-->
        <xsl:output method="html" indent="yes" encoding="iso-8859-1" media-type="html" doctype-public="-//W3C//DTD HTML 4.0//EN" />
    
        <xsl:template match="body">
    
            <!-- Page Content -->
            <div id="page-content-wrapper">
                <div class="container-fluid">
                </div>
    
            </div>
    
            <!-- content of other element -->
            <xsl:apply-templates select="footer" />
        </xsl:template>
    
    </xsl:stylesheet>
    

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <!-- header.xsl -->
        <xsl:template match="header">
            <!-- content of header -->
            <HEAD>
           </HEAD>
    
            <div class="container-fluid" id="top_section">
            </div>
            <!-- Sidebar -->
            <div id="sidebar-wrapper" class="hidden-print">
            </div>
            <!-- Modal -->
            <div id="myModalError" class="modal fade" role="dialog">
            </div>
    </xsl:template>
    
    
        <xsl:template name="footer">
            <FOOTER>
    
            </FOOTER>
        </xsl:template>
    
    </xsl:stylesheet>
    

    在firefox中,我在使用我的解决方案后看到了以下代码。

    <transformiix:result><head>....</head><body>....</body></transformiix:result>
    

    我正在使用php生成我放在上面的xml,并将其发送到浏览器。浏览器翻译样式表,并触发解决方法 document.ready 仅在firefox中,它将div放置在body标签内的正确位置。没有它,就没有身体标签。问题是:jquery无法定位body,因为它在firefox中是用transformiix封装的

    1 回复  |  直到 7 年前
        1
  •  1
  •   Martin Honnen    7 年前

    您当前的XSLT不会创建HTML根元素,因此请将主样式表更改为,例如。

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
        <xsl:import href="header.xsl" />
    
    
        <xsl:output method="html" indent="yes" doctype-system="about:legacy-doctype"/>
    
        <xsl:template match="/">
          <html>
            <xsl:apply-templates/>
          </html>
        </xsl:template>
    
        <xsl:template match="body">
    
            <!-- Page Content -->
            <div id="page-content-wrapper">
                <div class="container-fluid">
                </div>
    
            </div>
    
            <!-- content of other element -->
            <xsl:apply-templates select="footer" />
        </xsl:template>
    
    </xsl:stylesheet>
    

    这应该可以避免 transformiix:result 正在添加的元素。我认为您的方法还存在其他问题,无法生成有效的HTML,但修复这些问题并不像您希望输出HTML结果元素那样容易 div