Closed GoogleCodeExporter closed 9 years ago
Although it should work in main cases, I don't like madHacker solution. So here
is my
solution :
I delete the "item:null" template and I add a condition in the "object"
template to
match null child nodes :
--code--
<!-- item:null : DELETED
<xsl:template match="*[count(child::node())=0]">
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="local-name()"/>
</xsl:call-template>
<xsl:text>:null</xsl:text>
<xsl:if test="following-sibling::*">,</xsl:if>
</xsl:template>
-->
<!-- object -->
<xsl:template match="*" name="base">
<xsl:if test="not(preceding-sibling::*)">{</xsl:if>
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="name()"/>
</xsl:call-template>
<xsl:text>:</xsl:text>
<!-- check type of node -->
<xsl:choose>
<!-- null nodes -->
<xsl:when test="count(child::node())=0">null</xsl:when>
<!-- other nodes -->
<xsl:otherwise>
<xsl:apply-templates select="child::node()"/>
</xsl:otherwise>
</xsl:choose>
<!-- end of type check -->
<xsl:if test="following-sibling::*">,</xsl:if>
<xsl:if test="not(following-sibling::*)">}</xsl:if>
</xsl:template>
--end of code--
I performed some tests and it seems to be ok.
Original comment by mat.per...@gmail.com
on 21 May 2007 at 2:08
Attachments:
Thanks, this appears to fix a problem I was experiencing where invalid
javascript was
being generated by some tags.
<slideshow>
<item id="0" type="WebLink">
<title><![CDATA[Pay The Devil]]></title>
<other><![CDATA[New Release]]></other>
<asset-subtypes>
<asset-subtype/>
</asset-subtypes>
...
was generating code that looked like:
{"slideshow":[{"title":"Pay The Devil","other":"New
Release","asset-subtypes":"asset-subtype":null,
the part:
"asset-subtypes":"asset-subtype":null
obviously was invalid.
The new xslt fixes it :-)
WooHoo!
thanks
Original comment by pauleda...@gmail.com
on 5 Dec 2007 at 6:53
just add the last line
<xsl:if test="not(following-sibling::*)">}</xsl:if>
that was missing in the item:null template
<!-- item:null -->
<xsl:template match="*[count(child::node())=0]">
<xsl:call-template name="escape-string">
<xsl:with-param name="s" select="local-name()"/>
</xsl:call-template>
<xsl:text>:null</xsl:text>
<xsl:if test="following-sibling::*">,</xsl:if>
<xsl:if test="not(following-sibling::*)">}</xsl:if>
</xsl:template>
Original comment by deviants...@gmail.com
on 6 Mar 2008 at 10:55
Fixed in r22.
Original comment by docw...@gmail.com
on 31 Mar 2008 at 4:43
Original issue reported on code.google.com by
madhac...@gmail.com
on 17 Apr 2007 at 7:46Attachments: