Rao E
Rao E

Reputation: 1

Trying to pull back the expected value between two conditions

XML:

Below is the sample XML trying below 2 ways but doesn't return any value. Am I doing Something wrong on Template match or condition

<root>
    <Pol>
        <InsOrPrincipal>
            <General>
                <Addr>
                    <StateProvCd CodeListRef="StateOrProvince">CT</StateProvCd>
                </Addr>
            </General>
        </InsOrPrincipal>
        <CPol>
            <Controlling CodeListRef="StateOrProvince">OH</Controlling>
        </CPol>
    </Pol>
</root>
<xsl:template match="*:Pol">
<!-- Solution 1>
<xsl:value-of select= "if(string-length(normalize-space(*:CPol/*:Controlling/@*:CodeListRef))&gt;0) then (*:CPol/*:Controlling/@*:CodeListRef, *:Controlling) else (*:StateProvCd/@*:CodeListRef, *:StateProvCd)"/>
<!-- Solution 2>
<xsl:choose>
    <xsl:when test="*:CPol/*:Controlling">
        <xsl:value-of select="fns:listValue(*:Controlling/@*:CodeListRef, *:Controlling)"/>
    </xsl:when>
    <xsl:when test="*:InsOrPrincipal/*:General/*:Addr">
        <xsl:value-of select="fns:listValue(*:StateProvCd/@*:CodeListRef, *:StateProvCd)"/>
    </xsl:when>
    <xsl:otherwise/>
</xsl:choose>
</xsl:template>

Upvotes: 0

Views: 27

Answers (1)

Martin Honnen
Martin Honnen

Reputation: 167401

For me, the example

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="3.0"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="#all">

<xsl:template match="*:Pol">
  <xsl:value-of select= "if(string-length(normalize-space(*:CPol/*:Controlling/@*:CodeListRef))&gt;0) then (*:CPol/*:Controlling/@*:CodeListRef, *:Controlling) else (*:StateProvCd/@*:CodeListRef, *:StateProvCd)"/>
</xsl:template>
  
</xsl:stylesheet>

at the online fiddle outputs StateOrProvince.

It is not clear what you want to select/check but I suspect that it's more like

<xsl:template match="*:Pol">
  <xsl:value-of 
    select="if(string-length(normalize-space(*:CPol/*:Controlling/@*:CodeListRef))&gt;0)
            then *:CPol/*:Controlling/(@*:CodeListRef, .) else .//*:StateProvCd/(@*:CodeListRef, .)"/>
</xsl:template>

Upvotes: 0

Related Questions