Permalink
Browse files

added json output

  • Loading branch information...
1 parent ee9d1bf commit b6b71f99b8f6d3ae991b3451da707f592046921b planet-php committed Jan 8, 2010
Showing with 52 additions and 1 deletion.
  1. +7 −1 sitemap/sitemap.xml
  2. +45 −0 xsl/json.xsl
View
@@ -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">
View
@@ -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.