Reputation: 473
Generally tag contains XML and \XML in my case some node contains xml/.
Thi is my XML:
<NTC_LIGHTLISTPRODUCT>
<RACON>
<RACON_CATEGORY>Racon</RACON_CATEGORY>
<RACON_GROUP>Mo(M)</RACON_GROUP>
<RACON_PERIOD>30s</RACON_PERIOD>
<RACON_RANGE>10M</RACON_RANGE>
<RACON_WAVE_LENGTH>0.03-X,0.10-S</RACON_WAVE_LENGTH>
</RACON>
</NTC_LIGHTLISTPRODUCT>
<NTC_LIGHTLISTPRODUCT>
<RACON/> <-- This is the problem -->
</NTC_LIGHTLISTPRODUCT>
This is my xslt 1.0:
<xsl:for-each select="NTC_LIGHTLISTPRODUCT">
<xsl:for-each select="RACON">
CIAO
<xsl:for-each select="RACON_GROUP">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="RACON_PERIOD">
<xsl:value-of select="."/>
</xsl:for-each>
<xsl:for-each select="RACON_RANGE">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:for-each>
</xsl:for-each>
This is the output:
ciao Mo(M)30s10M
ciao
I would that if contains RACON/ don't write nothing. I would that this process run only for structure RACON..... /RACON, not for RACON/.
Upvotes: 0
Views: 25
Reputation: 70618
I think what you are saying is that you don't want to process RACON
elements that don't have children. In which case, change the xsl:for-each
to this:
<xsl:for-each select="RACON[*]">
Or perhaps you can be more specific, and check it contains at least one of the child elements you wish to output. For example:
<xsl:for-each select="RACON[RACON_GROUP or RACON_PERIOD or RACON_RANGE]">
And if you wanted to go further, you could check at least one of the child elements has at least some text in it
<xsl:for-each select="RACON[normalize-space(RACON_GROUP) or normalize-space(RACON_PERIOD) or normalize-space(RACON_RANGE)]">
Upvotes: 1