Répétition du nom du child name après la transformation XSL
Bonjour :D:D:D
Dans mon XML il peut y avoir plusieurs fois la donnée garantie / entité / personne qui contiennent plusieurs valeurs.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| "sinistre":{
"codePays":"FRA",
"description":"le sinistre a été ouvert",
"codeAuto":"N",
"garantie":[ {
"codeGarantie":"REC",
"typeDommage":"M",
"nombreVehiculeTiers":"1",
"nombreTiers":"A"
},{
"codeGarantie":"REC",
"typeDommage":"M",
"nombreVehiculeTiers":"1",
"nombreTiers":"A"
}
]
}, |
Ci-dessous mon XSL j'ai réussi à mettre en place la prise en compte de plusieurs garanties possibles mais j'ai un problème de transformation
XSL :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
| <!-- Object or Element Property-->
<xsl:template match="*">"<xsl:value-of select="name()"/>":<xsl:call-template name="Properties"/></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:value-of select="."/>"</xsl:when>
<xsl:when test="count(*[name()=$childName]) > 1">{"<xsl:value-of select="$childName"/>":[<xsl:apply-templates select="*" mode="ArrayElement"/>]}</xsl:when>
<xsl:when test="(name() = 'garantie' or name() = 'entite' or name() = 'personne')and count(*[name()=$childName]) = 1">[{<xsl:apply-templates select="@*"/><xsl:apply-templates select="*"/>}]</xsl:when>
<xsl:otherwise>{<xsl:apply-templates select="@*"/><xsl:apply-templates select="*"/>}</xsl:otherwise>
</xsl:choose>
<xsl:if test="following-sibling::*">,</xsl:if>
</xsl:template>
<!-- Attribute Property -->
<xsl:template match="@*">"<xsl:value-of select="name()"/>" : "<xsl:value-of select="."/>",</xsl:template>
</xsl:stylesheet> |
Transformation souhaitée :
Code:
1 2
| "garantie":[{"codeGarantie":"REC","typeDommage":"M","nombreVehiculeTiers":"1","nombreTiers":"A"},
{"codeGarantie":"REC","typeDommage":"C","nombreVehiculeTiers":"1","nombreTiers":"13"},{"codeGarantie":"DOT","typeDommage":"M","nombreVehiculeTiers":"0","nombreTiers":"13"}]}, |
Transformation que j'ai :(
Code:
1 2
| "garantie":[{"codeGarantie":"INC","typeDommage":"M","nombreVehiculeTiers":"0","nombreTiers":"0"}],
"garantie":[{"codeGarantie":"TES","typeDommage":"M","nombreVehiculeTiers":"1","nombreTiers":"1"}]}, |
le nom "garantie" revient à chaque fois ... alors que j'aimerais juste avoir },{ entre les 2 garanties avec uniquement les infos contenues dans Garantie
Merci pour votre aide, je débute :oops::oops: