2017-05-28 53 views
2

我想寫XSL樣式表的結果轉變成一個簡單的純文本字符串,我得到在Chrome以下錯誤和Opera如何使用nginx在XSL轉換的樣式表上獲取「text/plain」輸出?

此頁面包含以下錯誤:

第1行第1列的錯誤:文檔末尾的額外內容 下面是頁面渲染到第一個錯誤。

本文檔是作爲XSL轉換的結果而創建的。給出的 行和列號來自轉換後的結果。

雖然它在Firefox的工作正常

爲什麼?

的XSL是:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:template match="/"> 
     <xsl:apply-templates select="rtmp"/> 
    </xsl:template> 

    <xsl:template match="rtmp"> 
     <xsl:apply-templates select="server"/> 
    </xsl:template> 

    <xsl:template match="server"> 
     <xsl:apply-templates select="application"/> 
    </xsl:template> 

    <xsl:template match="application"> 
     <xsl:apply-templates select="live"/> 
    </xsl:template> 

    <xsl:template match="live"> 
     <xsl:apply-templates select="stream"/> 
    </xsl:template> 

    <xsl:template match="stream"> 
     <xsl:choose> 
      <xsl:when test="publishing"><xsl:value-of select="name"/>:<xsl:value-of select="nclients - 1"/>, 
      </xsl:when> 
     </xsl:choose> 

    </xsl:template> 

</xsl:stylesheet> 

和nginx的CONF是:

location /live { 
    rtmp_stat all; 
    rtmp_stat_stylesheet live.xsl; 
    include mime.types; 
    default_type text/plain; 
} 
location /live.xsl { 
    root /usr/local/nginx/html/; 
} 

的目的實際上是從nginx RTMP module檢索結果。

我在Firefox頁面打開了View Page Info,類型是「text/xml」。我認爲,如果我能讓它看起來像「文本/簡單」,它就能解決問題。但是如何?我可以在nginx或XSL樣式表中配置它嗎?

我想收到一個200狀態的文本/純字符串。

+0

可能是你可以試試https://stackoverflow.com/a/44218015/6229548 –

回答

3

現在你的樣式表的輸出是一個xml文檔,它不能以文本開頭,所以Opera和Chrome決定投訴。

添加

<xsl:output method="text"/> 

到您的樣式表<stylesheet>元素下面聲明輸出爲文本。