1

I am brand new to xml and xsl. I have a question relating to xsl:value-of select

Is there a way to insert a type of "isnull", meaning that if one value is empty it should hide that tag and use another one?

Example of the code:

      <ExternalIdentifier>
        <!-- Id number -->
        <TypeCode>IdentityDocumentId </TypeCode>
        <Id>
          <xsl:value-of select="idy_nbr"/>
        </Id>
      </ExternalIdentifier>

I need to change it to something like this (but it should hide the IdentityDocumentId tag if there is no value and use the Passport Number tag instead :

  <ExternalIdentifier>
    <!-- Id number -->
    <TypeCode>IdentityDocumentId </TypeCode>
    <Id>
      <xsl:value-of select="idy_nbr"/>
    </Id>
    <TypeCode>Passport Number</TypeCode>
    <Id>
      <xsl:value-of select="ppo_nbr"/>
    </Id>
  </ExternalIdentifier>

Thank you.

2 Answers 2

1

This is what template rules are for:

<xsl:apply-templates select="idy_nbr, "pro_nbr"/>

<xsl:template match="idy_nbr">
   <TypeCode>IdentityDocumentId</TypeCode>
   <Id>
       <xsl:value-of select="idy_nbr"/>
   </Id>
</xsl:template>

<xsl:template match="pro_nbr">
   <TypeCode>Passport Number</TypeCode>
   <Id>
       <xsl:value-of select="pro_nbr"/>
   </Id>
</xsl:template>
Sign up to request clarification or add additional context in comments.

Comments

0

I suppose you want something like:

<ExternalIdentifier>
    <xsl:choose>
        <xsl:when test="string(idy_nbr)">
            <TypeCode>IdentityDocumentId</TypeCode>
            <Id>
                <xsl:value-of select="idy_nbr"/>
            </Id>
        </xsl:when>
        <xsl:otherwise>
            <TypeCode>Passport Number</TypeCode>
            <Id>
                <xsl:value-of select="ppo_nbr"/>
            </Id>
        </xsl:otherwise>
    </xsl:choose>
</ExternalIdentifier>

Untested because no input example was provided.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.