ikevin8me
ikevin8me

Reputation: 4313

How to get a "text/plain" output on a XSL transformed stylesheet with nginx?

I'm trying to write XSL stylesheet to transform result into a simple plain text string, and I'm getting the following error on Chrome and Opera:

This page contains the following errors:

error on line 1 at column 1: Extra content at the end of the document Below is a rendering of the page up to the first error.

This document was created as the result of an XSL transformation. The line and column numbers given are from the transformed result.

while it works fine on Firefox.

Why?

The XSL is:

<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>

and the nginx conf is:

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/;
}

The purpose is actually to retrieve the result from nginx RTMP module.

I opened up View Page Info on the Firefox page and the type is "text/xml". I think if I can make it appear as "text/plain" it would solve the problem. But how? Can I configure this in nginx or in the XSL stylesheet?

I'd like to receive a text/plain string with a 200 status.

Upvotes: 2

Views: 869

Answers (1)

wero
wero

Reputation: 32980

Right now the output of your stylesheet is a xml document and it can't start with text, so Opera and Chrome decide to complain.

Add a

<xsl:output method="text"/>

to your stylesheet below the <stylesheet> element to declare the output as text.

Upvotes: 3

Related Questions