尝试拉回两个条件之间的期望值

问题描述 投票:0回答:1

XML:

下面是尝试以下两种方法但不返回任何值的示例 XML。我在模板匹配或条件上做错了什么吗

<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>
xslt-2.0 xpath-2.0
1个回答
0
投票

对于我来说,这个例子

<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>

在线小提琴输出

StateOrProvince

不清楚您要选择/检查什么,但我怀疑它更像是

<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>
© www.soinside.com 2019 - 2024. All rights reserved.