Skip to content

Commit

Permalink
Aggiunta gestione numeri e booleans
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Togno committed Jan 23, 2018
1 parent 2d2962c commit 8cd74b5
Showing 1 changed file with 61 additions and 42 deletions.
103 changes: 61 additions & 42 deletions GLOBAL.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>

<!-- Object Properties -->
<xsl:template name="PropertiesRow">
<xsl:apply-templates mode="ArrayElement" select="Row"/>
</xsl:template>

<!-- find element start with LIST and have a child with name Rowset-->
<xsl:template match="*[starts-with(name(), 'LIST_')]">
<xsl:text>"</xsl:text>
Expand All @@ -35,7 +35,7 @@
<xsl:text>:[</xsl:text>
<xsl:choose>
<xsl:when test="name(*[*]) = 'Rowset'">
<xsl:call-template name="PropertiesNestedObject"/>
<xsl:call-template name="PropertiesNestedObject"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="PropertiesList"/>
Expand All @@ -46,30 +46,49 @@
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>

<!-- List Properties -->
<xsl:template name="PropertiesList">
<xsl:apply-templates mode="ArrayElement" select="*"/>
</xsl:template>

<!-- List PropertiesNestedObject -->
<xsl:template name="PropertiesNestedObject">
<xsl:apply-templates mode="ArrayElement" select="*/Row"/>
</xsl:template>

<!-- Array Element -->
<xsl:template match="*" mode="ArrayElement">
<xsl:call-template name="Properties"/>
</xsl:template>

<!-- Object Properties -->
<xsl:template name="Properties">
<xsl:variable name="childName" select="name(*[1])"/>
<xsl:choose>
<xsl:when test="not(*)">
<xsl:text>"</xsl:text>
<xsl:call-template name="jsonTextEscape"/>
<xsl:text>"</xsl:text>

<xsl:variable name="valore" select="."/>
<xsl:choose>
<xsl:when test="number($valore) = $valore">
<!-- Senza apici per numerici e booleani -->
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="$valore = 'true'">
<!-- Senza apici per numerici e booleani -->
<xsl:value-of select="."/>
</xsl:when>
<xsl:when test="$valore = 'false'">
<!-- Senza apici per numerici e booleani -->
<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
<!-- Apici per stringhe -->
<xsl:text>"</xsl:text>
<xsl:call-template name="jsonTextEscape"/>
<xsl:text>"</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="count(*[name()=$childName]) &gt; 1">
<xsl:text>{"</xsl:text>
Expand All @@ -88,46 +107,46 @@
<xsl:text>,</xsl:text>
</xsl:if>
</xsl:template>

<xsl:template name="jsonTextEscape">
<xsl:call-template name="escapeQuote">
<xsl:with-param name="pText">
<xsl:call-template name="jsonescape">
<xsl:with-param name="str" select="." />
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="pText">
<xsl:call-template name="jsonescape">
<xsl:with-param name="str" select="." />
</xsl:call-template>
</xsl:with-param>
</xsl:call-template>
</xsl:template>

<xsl:template name="escapeQuote">
<xsl:param name="pText" select="concat(normalize-space(.), '')" />
<xsl:template name="escapeQuote">
<xsl:param name="pText" select="concat(normalize-space(.), '')" />
<xsl:if test="string-length($pText) >0">
<xsl:value-of select="substring-before(concat($pText, '&quot;'), '&quot;')" />
<xsl:value-of select="substring-before(concat($pText, '&quot;'), '&quot;')" />

<xsl:if test="contains($pText, '&quot;')">
<xsl:text>\"</xsl:text>
<xsl:call-template name="escapeQuote">
<xsl:with-param name="pText" select="substring-after($pText, '&quot;')" />
</xsl:call-template>
</xsl:if>

<xsl:if test="contains($pText, '&quot;')">
<xsl:text>\"</xsl:text>
<xsl:call-template name="escapeQuote">
<xsl:with-param name="pText" select="substring-after($pText, '&quot;')" />
</xsl:call-template>
</xsl:if>

</xsl:if>
</xsl:template>
</xsl:if>
</xsl:template>

<xsl:template name="jsonescape">
<xsl:param name="str" select="."/>
<xsl:choose>
<xsl:when test="contains($str, '\')">
<xsl:value-of select="concat(substring-before($str, '\'), '\\' )"/>
<xsl:call-template name="jsonescape">
<xsl:with-param name="str" select="substring-after($str, '\')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="jsonescape">
<xsl:param name="str" select="."/>
<xsl:choose>
<xsl:when test="contains($str, '\')">
<xsl:value-of select="concat(substring-before($str, '\'), '\\' )"/>
<xsl:call-template name="jsonescape">
<xsl:with-param name="str" select="substring-after($str, '\')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$str"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<!-- Attribute Property -->
<xsl:template match="@*">
<xsl:text>"@</xsl:text>
Expand Down

0 comments on commit 8cd74b5

Please sign in to comment.