doekman / xml2json-xslt

Automatically exported from code.google.com/p/xml2json-xslt
BSD 3-Clause "New" or "Revised" License
38 stars 17 forks source link

Glitch with null things in an object list. #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. If there's a null item at the end of an object list, the closing curly
brackets aren't reproduced exactly.
2. Also I find that the code to test the following items doesn't work
exactly right.  

<object>
  <thing> test </thing>
  <nullpart/>
</object>

What is the expected output? What do you see instead?

What version of the product are you using? On what operating system?

Please provide any additional information below.

Here's my new version. Note the tags at the end of each case:

 <!-- item:null -->
  <xsl:template match="*[count(child::node())=0]">
    <xsl:call-template name="indent"/>
    <xsl:call-template name="quote-property">
      <xsl:with-param name="name" select="local-name()"/>
    </xsl:call-template>
    <xsl:text>:null</xsl:text>
     <xsl:choose>
    <xsl:when   test="following-sibling::*">,</xsl:when>
    <xsl:otherwise >}</xsl:otherwise>
     </xsl:choose>
  </xsl:template>

  <!-- object -->
  <xsl:template match="*" name="base">
    <xsl:if test="not(preceding-sibling::*)">{</xsl:if>
    <xsl:call-template name="indent"/>
    <!-- JS: handle attributes -->
    <xsl:call-template name="attrs">
      <xsl:with-param name="attrs" select="../@*"/>
    </xsl:call-template>
    <xsl:call-template name="quote-property">
      <xsl:with-param name="name" select="name()"/>
    </xsl:call-template>
    <xsl:text>:</xsl:text>
    <xsl:apply-templates select="child::node()"/>
    <xsl:choose>
    <xsl:when   test="following-sibling::*">,</xsl:when>
    <xsl:otherwise >}</xsl:otherwise>
     </xsl:choose>
  </xsl:template>

  <!-- array -->
  <xsl:template match="*[count(../*[name(../*)=name(.)])=count(../*) and
count(../*)&gt;1]">
    <xsl:if test="not(preceding-sibling::*)">[</xsl:if>
    <xsl:call-template name="indent"/>
    <xsl:choose>
      <xsl:when test="not(child::node())">
        <xsl:text>null</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="child::node()"/>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:choose>
    <xsl:when   test="following-sibling::*">,</xsl:when>
    <xsl:otherwise >]</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

Original issue reported on code.google.com by pway...@gmail.com on 17 Apr 2008 at 2:25