xslt:css无法在html页面中启动

时间:2019-04-25 10:20:41

标签: html css spring-mvc xslt xsltviewresolver

在春季项目中,我正在使用XsltViewResolver将xml转换为html org.springframework.web.servlet.view.xslt.XsltViewResolver

在html中,css无法输出代码。
XML字符串:

<?xml version="1.0"?>
<kblc:kblcImportLc xmlns:kblc='http://www.kblc.com/schema/v1/kblc'>
    <kblc:ImportStructureLC>
        <kblc:ImportLCHeader>
            <kblc:ApplicantInfo>
                <kblc:ApplicantName>ApplicantTest</kblc:ApplicantName>
                <kblc:ApplicantAddress>Spring Villa Park</kblc:ApplicantAddress>
                <kblc:ApplicantCity>London</kblc:ApplicantCity>
                <kblc:ApplicantPostalCode>HA8 7EB</kblc:ApplicantPostalCode>
                <kblc:ApplicantCountry>UK</kblc:ApplicantCountry>
                <kblc:ApplicantRegion>consistent</kblc:ApplicantRegion>
                <kblc:ApplicantContactName>AA</kblc:ApplicantContactName>
                <kblc:ApplicantEmail>email@mail.com</kblc:ApplicantEmail>
                <kblc:ApplicantPhone>5856965456</kblc:ApplicantPhone>
                <kblc:ApplicantFax>021548795</kblc:ApplicantFax>
            </kblc:ApplicantInfo>
        </kblc:ImportLCHeader>
    </kblc:ImportStructureLC>
</kblc:kblcImportLc>

XSL文件:

<?xml version="1.0"?>
<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:kblc="http://www.kblc.com/schema/v1/kblc">
    <xsl:output method="html" version="4.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <head>
                <title>Sports Info</title>
                <style>
                    .HelpTitle {
                    font: 13px verdana, sans-serif;
                    font-weight: bold;
                    text-decoration: underline;
                    margin-left: 5px;
                    margin-right: 5px;
                    }
                    .HelpText {
                    font: 11px verdana, sans-serif;
                    margin-left: 5px;
                    margin-right: 5px;
                    }
                    .HelpHighlight {
                    background-color: #55be28 ;
                    }
                </style>
                <script language="javascript" type="text/javascript">
                    function init () {
                    var url = new URL(document.location);
                    var str2 = url.searchParams.get("tagName");

                    document.getElementById(str2).className = "HelpHighlight";
                    document.getElementById("ErrorString").value="someContent";
                    document.getElementById("ErrorString123").value=str2;
                    document.getElementById(str2).focus();
                    }
                </script>
            </head>
            <body onload="init();">
                <xsl:apply-templates/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="kblc:kblcImportLc/kblc:ImportStructureLC">
        <!-- Start ApplicantName -->
        <div id="ApplicantName">
            <br/>
            <div class="HelpTitle">ApplicantName</div>
            <br/>
            <div class="HelpText">
                <xsl:value-of select="kblc:ImportLCHeader/kblc:ApplicantInfo/kblc:ApplicantName" />
            </div>
            <div id="ErrorString123"></div>
            <br/>
        </div>
        <!-- End ApplicantName -->


        <!-- Start ApplicantAddress -->
        <div id="ApplicantAddress">
            <br/>
            <div class="HelpTitle">ApplicantAddress</div>
            <br/>
            <div class="HelpText">
                <xsl:value-of select="kblc:ImportLCHeader/kblc:ApplicantInfo/kblc:ApplicantAddress" />
            </div>
            <div id="ErrorString"></div>
            <br/>
        </div>
        <!-- End ApplicantAddress -->

    </xsl:template>
</xsl:stylesheet>

HTML输出:

<html xmlns:kblc="http://www.kblc.com/schema/v1/kblc">
  <head>
    <META http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Sports Info</title>
    <style>
                    .HelpTitle {
                    font: 13px verdana, sans-serif;
                    font-weight: bold;
                    text-decoration: underline;
                    margin-left: 5px;
                    margin-right: 5px;
                    }
                    .HelpText {
                    font: 11px verdana, sans-serif;
                    margin-left: 5px;
                    margin-right: 5px;
                    }
                    .HelpHighlight {
                    background-color: #55be28 ;
                    }
                </style>
    <script type="text/javascript" language="javascript">
                    function init () {
                    var url = new URL(document.location);
                    var str2 = url.searchParams.get("tagName");

                    document.getElementById(str2).className = "HelpHighlight";
                    document.getElementById("ErrorString").value="someContent";
                    document.getElementById("ErrorString123").value=str2;
                    document.getElementById(str2).focus();
                    }
                </script>
  </head>
  <body onload="init();">

    <div id="ApplicantName">
      <br>
      <div class="HelpTitle">ApplicantName</div>
      <br>
      <div class="HelpText">ApplicantTest</div>
      <div id="ErrorString123"></div>
      <br>
    </div>
    <div id="ApplicantAddress">
      <br>
      <div class="HelpTitle">ApplicantAddress</div>
      <br>
      <div class="HelpText">Spring Villa Park</div>
      <div id="ErrorString"></div>
      <br>
    </div>


  </body>
</html>

在此html中,css无法正常工作。

1 个答案:

答案 0 :(得分:1)

来自评论

  

html标记具有名称空间,这是因为CSS无法正常工作吗?

事实并非如此。但是,如果您不想在HTML文档中输出该奇怪的名称空间声明,请在xsl:stylesheet元素中使用exclude-result-prefixes atribute

<xsl:stylesheet version="2.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:kblc="http://www.kblc.com/schema/v1/kblc"
                exclude-result-prefixes="kblc">