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.
CodePudding user response:
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>
CodePudding user response:
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.