Reputation: 107
I am working with some XML files where in some instances the HName node is available in some files while missing from the others. Here are two examples:
Xml #1:
<HSegment>
<Code>ABC</Code>
</HSegment>
Xml #2:
<HSegment>
<Code>ABC</Code>
<HName>JW BEACH</HName>
</HSegment>
I am trying to parse the xml files using two conditions:
The XSL code that i am working with below adds ‘NULL’ to both cases:
<Des>
<xsl:choose>
<xsl:when test="//PNR/SList/HSegment/HName='HName'">
</xsl:when>
<xsl:otherwise>
<xsl:text>NULL</xsl:text>
</xsl:otherwise>
</xsl:choose>
</Des>
Thanks in advance!
Upvotes: 1
Views: 57
Reputation: 60414
Modify the presence check to look like this:
//PNR/SList/HSegment/HName
In context:
<xsl:choose>
<xsl:when test="//PNR/SList/HSegment/HName">
<!-- do whatever -->
</xsl:when>
<xsl:otherwise>
<xsl:text>NULL</xsl:text>
</xsl:otherwise>
</xsl:choose>
Upvotes: 1