chenegar
asked on
XSLT: Prevent empty tags
I'd like to prevent empty tags from being created in my xml output. The input looks like this:
For output, I need this:
How can I skip those empty tags in my xml output?
<Answer name="HouseholdDemographics">
<RptValue>
<TextValue unans="true"/>
<TextValue unans="true"/>
<TextValue unans="true"/>
<TextValue>Disability within Household</TextValue>
</RptValue>
</Answer>
For output, I need this:
<DemographicList>
<Demographic>Disability within Household</Demographic>
</DemographicList>
but I'm getting this:<DemographicList>
<Demographic/>
<Demographic/>
<Demographic/>
<Demographic>Disability within Household</Demographic>
</DemographicList>
My transform code is currently this:<xsl:element name="DemographicList">
<xsl:apply-templates select="//Answer[@name='HouseholdDemographics']/RptValue/TextValue"></xsl:apply-templates>
</xsl:element>
and<xsl:template match="//Answer[@name='HouseholdDemographics']/RptValue/TextValue">
<xsl:variable name="getdemogs" select="position()"/>
<xsl:variable name="householddemog" select="//Answer[@name='HouseholdDemographics']//RptValue/TextValue[$getdemogs]"/>
<xsl:if test="normalize-space() or normalize-space($getdemogs)">
<xsl:element name="Demographic">
<xsl:value-of select="$householddemog"/>
</xsl:element>
</xsl:if>
</xsl:template>
How can I skip those empty tags in my xml output?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER