Skip to content

Commit

Permalink
added json output
Browse files Browse the repository at this point in the history
  • Loading branch information
planet-php committed Jan 8, 2010
1 parent ee9d1bf commit b6b71f9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
8 changes: 7 additions & 1 deletion sitemap/sitemap.xml
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,13 @@
<map:transform type="libxslt" src="BX_PROJECT_DIR://xsl/atom1.xsl"/>
<map:serialize type="xml"/>
</map:when>

<map:when test="/json*">
<map:transform type="libxslt" src="BX_PROJECT_DIR://xsl/json.xsl">
<map:parameter name="cb" value="phpglobals://_GET[cb]" default="0"/>
<map:parameter type="options" name="registerPhpFunctions" value="'true'"/>
</map:transform>
<map:serialize type="json"/>
</map:when>

<map:otherwise>
<map:transform type="libxslt" src="BX_PROJECT_DIR://themes/{config://theme}/main.xsl">
Expand Down
45 changes: 45 additions & 0 deletions xsl/json.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:php="http://php.net/xsl"
>
<xsl:output method="xml" indent="no" omit-xml-declaration="no"/>

<xsl:param name="cb" />


<xsl:template match="/">
<xsl:if test="$cb != '0'">
<xsl:value-of select="$cb"/>(
</xsl:if>[<xsl:apply-templates select="/planet/entries/entry"/>]
<xsl:if test="$cb != '0'">);
</xsl:if>
</xsl:template>

<xsl:template match="entries/entry">{"title": <xsl:value-of select="php:functionString('json_encode',title)"/>,
"link": <xsl:value-of select="php:functionString('json_encode',link)"/>,
"author": <xsl:choose>
<xsl:when test="string-length(blog_author) &gt; 0 ">
<xsl:value-of select="php:functionString('json_encode',blog_author)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="php:functionString('json_encode',blog_title)"/>
</xsl:otherwise>
</xsl:choose>,
"guid": <xsl:value-of select="php:functionString('json_encode',guid)"/>,
"updated": <xsl:value-of select="php:functionString('json_encode',date_iso)"/>,
"content": <xsl:call-template name="description"/>,
"id": <xsl:value-of select="id"/>
}<xsl:if test="position() != last()">,</xsl:if>
</xsl:template>

<xsl:template name="description">
<xsl:choose>
<xsl:when test="string-length(content_encoded) > 0">
<xsl:value-of disable-output-escaping="yes" select="php:functionString('json_encode',content_encoded)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of disable-output-escaping="yes" select="php:functionString('json_encode',description)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>

0 comments on commit b6b71f9

Please sign in to comment.