1

I have a xml like:

<EnhancedData>
                  <EmailAddress>[email protected]</EmailAddress>
                  <PassengerName>ABC/DEF</PassengerName>
                  <RecordLocator_PNR>ABCDEF</RecordLocator_PNR>
</EnhancedData>

Corresponding XSLT that I am using looks like:

<xsl:for-each select="EnhancedData">
            <xsl:if test="*">
              <EnhancedData>
                <xsl:value-of select="Y" />
              </EnhancedData>
            </xsl:if>
          </xsl:for-each>
          <xsl:for-each select="EnhancedData/EmailAddress">
          <EmailAddress>
          <xsl:value-of select="." />
          </EmailAddress>
          </xsl:for-each>
           <xsl:for-each select="EnhancedData/PassengerName">
          <PassengerName>
          <xsl:value-of select="." />
          </PassengerName>
          </xsl:for-each>
           <xsl:for-each select="EnhancedData/RecordLocator_PNR">
          <RecordLocator_PNR>
          <xsl:value-of select="." />
          </RecordLocator_PNR>
          </xsl:for-each>

I am using a Java code which transforms the xml into another o/p file using the XSLT. I need to make Enhanced Data as Y, if it contains any child node.

With the current code, the output xml looks like:

<EnhancedData/>
<EmailAddress>[email protected]</EmailAddress>
<PassengerName>ABC/DEF</PassengerName>
<RecordLocator_PNR>ABCDEF</RecordLocator_PNR>

What I need is :

<EnhancedData>Y</EnhancedData>
<EmailAddress>[email protected]</EmailAddress>
<PassengerName>ABC/DEF</PassengerName>
<RecordLocator_PNR>ABCDEF</RecordLocator_PNR>

1 Answer 1

0

Instead of

<xsl:value-of select="Y" />

just use

<xsl:text>Y</xsl:text>
1
  • The following code works: <xsl:choose> <xsl:when test="EnhancedData/PassengerName != ''"> <EnhancedData>Y</EnhancedData> </xsl:when> <xsl:otherwise> <EnhancedData>N</EnhancedData> </xsl:otherwise> </xsl:choose> Nov 21, 2013 at 9:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.