xpath optional attribute with inner attributes



I have this xml with a nested element which is optional and I have to make a csv file with attributes from the hierarchy even when the optional attribute is not present.


here is the xml data file:



<dataroot xmlns:xsi="http://ift.tt/ra1lAU" xmlns="http://ift.tt/1xcff8U">
<ELEMENTS>
<COUNTRY cod_cnt="030">
<AS cod_as="030308">
<CONTRACT num_CONTRACT="8715167"/>
<CONTRACT num_CONTRACT="8715224"/>
</AS>
<AS cod_as="030309"/>
</COUNTRY>
</ELEMENTS>
</dataroot>


suppose i need the elements that have a CONTRACT tag and the AS tag even if it hasn't a CONTRACT child. I've wrote something like that but I'm stuck:



<xsl:for-each select="/doc:dataroot/doc:ELEMENTS/doc:COUNTRY/doc:AS/doc:CONTRACT">
<xsl:value-of select="../../@cod_cnt"/>@<xsl:value-of select="../@cod_as"/>
@<xsl:value-of select="@num_CONTRACT"/>@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@0@D<xsl:text> </xsl:text>
</xsl:for-each>


I know I miss a sort of union but can't go further.


No comments:

Post a Comment