Skip to content

empty nodes in a list break the json. #12

Open
@GoogleCodeExporter

Description

@GoogleCodeExporter
If you parse an xml like this.
<zoo>
  <fish>
    <name>whale</name>
    <weigth/>
  </fish>
  <bird>
    <name>owl</name>
  </bird>
</zoo>

it results in
{"fish":{"name":"whale", "weigth": null, "brid": {"name":"owl"}};

while it sould be
{"fish":{"name":"whale", "weigth": null}, "brid": {"name":"owl"}};

this is because in the item:null template there is no check if the item 
hasn't following sibings.

I fixed it for myself here is what is did:
  <!-- item:null -->
  <xsl:template match="*[count(child::node())=0]" mode="json">
    <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>
     <!-- fix by Cees van Wieringen
        We shoud use the same check as with an object, close the list with 
an '}' if there are no following-siblings.
     -->
    <xsl:if test="not(following-sibling::*)">}</xsl:if>
  </xsl:template>

Original issue reported on code.google.com by [email protected] on 19 Feb 2010 at 12:33

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions