Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

empty nodes in a list break the json. #12

Open
GoogleCodeExporter opened this issue Mar 19, 2015 · 1 comment
Open

empty nodes in a list break the json. #12

GoogleCodeExporter opened this issue Mar 19, 2015 · 1 comment

Comments

@GoogleCodeExporter
Copy link

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 cee...@gmail.com on 19 Feb 2010 at 12:33

@GoogleCodeExporter
Copy link
Author

I can't reproduce this. I also can't find any missing not(following-sibling::*) 
cases.

I did add unittests for this, though.

Original comment by docw...@gmail.com on 10 Mar 2010 at 7:20

  • Changed state: Started

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant