£和€错误XSLT

时间:2014-12-08 11:45:50

标签: xml xslt encoding

我们在尝试使用xslt模板查看格式化的xml时遇到错误。

xml是:

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="HandOffForms.xslt"?><form xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">  <requestor>ab000186</requestor> <depositList><deposit> <siteReference><![CDATA[1]]></siteReference> <postOffice><![CDATA[1]]></postOffice><tcRef><![CDATA[£]]></tcRef><depositDate>12/12/1212</depositDate><depositValue>1.00</depositValue></deposit></depositList></form>

XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" version="1.0"
encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <html>
            <body>
                <table border="1" width="720px">
                    <tr>
                        <th colspan="2" style="background-color:#E8E8E8;height:21px;border:0;border-top:1px solid #fff;margin:0;font-family:verdana;font-size: 11px;text-align:left;">Additional Information</th>
                    </tr>
                    <tr bgcolor="#F8F8F8">
                        <th style="font-family:verdana;font-size:11;text-align:left;color:#E80000;border:solid 1px #E80000">Attribute</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Value</th>
                    </tr>
                    <xsl:for-each select="form/*">

                    <xsl:variable name="nodoNombre" select="local-name()"></xsl:variable>

                    <xsl:if test="$nodoNombre!='depositList' and $nodoNombre!='chequeList' and $nodoNombre!='bagList'">
                    <tr>
                            <xsl:variable name="css-estilo">
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 1">font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#F1F1F1</xsl:when>
                                    <xsl:otherwise>font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#FFFFFF</xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                            <td style="{$css-estilo}">
                            <xsl:choose>
                                    <xsl:when test="local-name() = 'requestor'">Requestor</xsl:when>
                                    <xsl:when test="local-name() = 'queryType'">Query Type</xsl:when>
                                    <xsl:when test="local-name() = 'channel'">Channel</xsl:when>
                                    <xsl:when test="local-name() = 'siteReference'">Site Reference</xsl:when>
                                    <xsl:when test="local-name() = 'siteReference' or local-name() = 'siteRef'">Site Reference</xsl:when>
                                    <xsl:when test="local-name() = 'depositDate'">Deposit Date</xsl:when>
                                    <xsl:when test="local-name() = 'depositValue'">Deposit Value</xsl:when>
                                    <xsl:when test="local-name() = 'sitePost'">Site Post</xsl:when>
                                    <xsl:when test="local-name() = 'deliveryProof'">Delivery Proof</xsl:when>
                                    <xsl:when test="local-name() = 'discrepancyValue'">Discrepancy Value</xsl:when>
                                    <xsl:when test="local-name() = 'discrepancyDate'">Discrepancy Date</xsl:when>
                                    <xsl:when test="local-name() = 'valOrderPlaced'">Value Order Placed</xsl:when>
                                    <xsl:when test="local-name() = 'orderRefNumber'">Order Reference Number</xsl:when>  
                                    <xsl:when test="local-name() = 'valOrderReceived'">Value Order Received</xsl:when>  
                                    <xsl:when test="local-name() = 'G4S_site'">G4S site</xsl:when>
                                    <xsl:when test="local-name() = 'payeeHolding'">Payee Holding</xsl:when> 
                                    <xsl:when test="local-name() = 'contactName'">Contact Name</xsl:when>   
                                    <xsl:when test="local-name() = 'contactPhoneNum'">Contact Phone Number</xsl:when>                   
                                    <xsl:when test="local-name() = 'carrier'">Carrier</xsl:when>        
                                    <xsl:when test="local-name() = 'cageSealNumber'">Cage Seal Number</xsl:when>
                                    <xsl:otherwise>
                                        <xsl:value-of select="local-name()"/>
                                    </xsl:otherwise>
                                </xsl:choose>
                        </td>
                            <td style="{$css-estilo}">
                            <xsl:choose>
                                <xsl:when test="local-name() = 'discrepancyDate'">
                                    <xsl:call-template name="reformatDateTimeUKtoDate">
                                        <xsl:with-param name="dateTime" select="."/>
                                    </xsl:call-template>
                                </xsl:when>
                                <xsl:when test="local-name() = 'valOrderPlaced'">
                                    &#163; <xsl:value-of select="."/>
                                </xsl:when>
                                <xsl:when test="local-name() = 'valOrderReceived'">
                                    &#163; <xsl:value-of select="."/>
                                </xsl:when>
                                <xsl:when test="local-name() = 'depositValue'">
                                    &#163; <xsl:value-of select="."/>
                                </xsl:when>
                                <xsl:when test="local-name() = 'discrepancyValue'">
                                    &#163; <xsl:value-of select="."/>
                                </xsl:when>
                                <xsl:when test="local-name() = 'payeeHolding'">
                                    <xsl:call-template name="formatAcc">
                                        <xsl:with-param name="requestor" select="."/>
                                    </xsl:call-template>

                                </xsl:when>                                         
                                <xsl:otherwise>
                                    <xsl:value-of select="."/>
                                </xsl:otherwise>
                            </xsl:choose>
                            </td>
                        </tr>

                    </xsl:if>

                    <xsl:if test="$nodoNombre='depositList'">

                    <table border="1" width="720px">
                    <br></br>
                    <br></br>                   
                    <tr>
                        <!--<th colspan="2" style="font-family:verdana;font-size:11;text-align:left;background-color:#C0C0C0"><b>Additional Information</b></th>-->
                        <th colspan="5" style="background-color:#E8E8E8;height:21px;border:0;border-top:1px solid #fff;margin:0;font-family:verdana;font-size: 11px;text-align:left;">Deposit List</th>
                    </tr>
                    <tr bgcolor="#F8F8F8">
                        <th style="font-family:verdana;font-size:11;text-align:left;color:#E80000;border:solid 1px #E80000">Site Reference</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Post Office</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">TC Reference</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Deposit Date</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Deposit Value</th>
                    </tr>

                        <xsl:for-each select="/form/depositList/deposit">
                            <tr>
                            <xsl:variable name="css-estilo">
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 1">font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#F1F1F1</xsl:when>
                                    <xsl:otherwise>font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#FFFFFF</xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                        <td style="{$css-estilo}">

                                <xsl:value-of select="./siteReference"/>
                        </td>
                            <td style="{$css-estilo}">
                                <xsl:value-of select="./postOffice"/>
                            </td>

                            <td style="{$css-estilo}">
                                <xsl:value-of select="./tcRef"/>
                            </td>


                            <td style="{$css-estilo}">
                            <xsl:call-template name="reformatDateTimeUKtoDate">
                                            <xsl:with-param name="dateTime" select="./depositDate"/>
                            </xsl:call-template>
                            </td>


                            <td style="{$css-estilo}">
                                &#163; <xsl:value-of select="./depositValue"/>
                            </td>
                        </tr>
                        </xsl:for-each>

                    </table>
                    </xsl:if>


                    <xsl:if test="$nodoNombre='chequeList'">

                    <table border="1" width="720px">
                    <br></br>
                    <br></br>
                    <tr>
                        <!--<th colspan="2" style="font-family:verdana;font-size:11;text-align:left;background-color:#C0C0C0"><b>Additional Information</b></th>-->
                        <th colspan="3" style="background-color:#E8E8E8;height:21px;border:0;border-top:1px solid #fff;margin:0;font-family:verdana;font-size: 11px;text-align:left;">Cheque List</th>
                    </tr>
                    <tr bgcolor="#F8F8F8">
                        <th style="font-family:verdana;font-size:11;text-align:left;color:#E80000;border:solid 1px #E80000">Cheque Number</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Cheque Value</th>
                        <th style="font-family:verdana;font-size:11;text-align:center;color:#E80000;border:solid 1px #E80000">Cheque Date</th>
                    </tr>

                        <xsl:for-each select="/form/chequeList/cheque">
                            <tr>
                            <xsl:variable name="css-estilo">
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 1">font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#F1F1F1</xsl:when>
                                    <xsl:otherwise>font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#FFFFFF</xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                        <td style="{$css-estilo}">

                                <xsl:value-of select="./chequeNumber"/>
                        </td>
                            <td style="{$css-estilo}">
                                &#163; <xsl:value-of select="./chequeVal"/>
                            </td>

                            <td style="{$css-estilo}">
                                <xsl:call-template name="reformatDateTimeUKtoDate">
                                    <xsl:with-param name="dateTime" select="./chequeDate"/>
                            </xsl:call-template>
                            </td>

                        </tr>
                        </xsl:for-each>

                    </table>
                    </xsl:if>

                    <xsl:if test="$nodoNombre='bagList'">

                    <table border="1" width="720px">
                    <br></br>
                    <br></br>
                    <tr>
                        <!--<th colspan="2" style="font-family:verdana;font-size:11;text-align:left;background-color:#C0C0C0"><b>Additional Information</b></th>-->
                        <th colspan="3" style="background-color:#E8E8E8;height:21px;border:0;border-top:1px solid #fff;margin:0;font-family:verdana;font-size: 11px;text-align:left;">Bag list</th>
                    </tr>
                    <tr bgcolor="#F8F8F8">
                        <th style="font-family:verdana;font-size:11;text-align:left;color:#E80000;border:solid 1px #E80000">Bag Number</th>
                    </tr>

                        <xsl:for-each select="/form/bagList/*">
                            <tr>
                            <xsl:variable name="css-estilo">
                                <xsl:choose>
                                    <xsl:when test="position() mod 2 = 1">font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#F1F1F1</xsl:when>
                                    <xsl:otherwise>font-family:verdana;font-size:11;border:solid 0px #F0F0F0;background-color:#FFFFFF</xsl:otherwise>
                                </xsl:choose>
                            </xsl:variable>
                        <td style="{$css-estilo}">
                                <xsl:value-of select="."/>
                        </td>

                        </tr>
                        </xsl:for-each>

                    </table>
                    </xsl:if>                   

                    </xsl:for-each>
                </table>
            </body>
        </html>


    </xsl:template>
    <xsl:template name="reformatDateTimeUKtoDate">
        <!-- Expected format 20-08-2010 11:11:30:000000 -->
        <!-- Expected output 20-08-2010 -->
        <xsl:param name="dateTime"/>
        <xsl:value-of select="substring($dateTime,1,10)"/>
    </xsl:template>
    <xsl:template name="formatAcc">
        <xsl:param name="requestor"/>
        <xsl:value-of select="translate(substring-after($requestor, ':'), ':' , ' ')"/>
    </xsl:template>



</xsl:stylesheet>

问题在于获取包含£的tcRef标记。在本地ie即显示“£”:

enter image description here

哪个应该是正确的编码配置?

在我们的应用程序中尝试测试时,IE显示错误:

The XML page cannot be displayed 
Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later. 


--------------------------------------------------------------------------------

An invalid character was found in text content. Error processing resource 'http://abb.com...

<?xml version="1.0" encoding="UTF-8"?><?xml-stylesheet type="text/xsl" href="http://abb.com

enter image description here

1 个答案:

答案 0 :(得分:0)

也许服务器在Content-Type标头中发送了错误的字符集。如果是这样,请在模板中的<html>之后包含以下内容:

<head>
  <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
</head>