Xslt XSL如果列X是字符X,则执行此操作,否则执行此操作

Xslt XSL如果列X是字符X,则执行此操作,否则执行此操作,xslt,Xslt,-XSL版本1.0- 我有一个XSL文件,它是由不再在我的公司工作的人创建的,当然我们需要更改XSL。我从未使用过XSL,但做过一些搜索,我相信我可以通过使用choose函数更新XSL来执行所需的功能 -发行- 我们有一个字段,它的主角数从13变为11,但我们需要在一段时间内捕获这两个字段。决定删减今年的两位主角。值将保持不变,直到斜杠“/”为13或11个字符,后面的字符可以从5到13个字符不等 13个字符CTM08G2012001/0001 11个字符CTM08G12001/0001 我想

-XSL版本1.0-

我有一个XSL文件,它是由不再在我的公司工作的人创建的,当然我们需要更改XSL。我从未使用过XSL,但做过一些搜索,我相信我可以通过使用choose函数更新XSL来执行所需的功能

-发行- 我们有一个字段,它的主角数从13变为11,但我们需要在一段时间内捕获这两个字段。决定删减今年的两位主角。值将保持不变,直到斜杠“/”为13或11个字符,后面的字符可以从5到13个字符不等

  • 13个字符CTM08G2012001/0001
  • 11个字符CTM08G12001/0001
我想检查第12个字符是否是“/”,如果是,请使用前11个字符,如果不是,请使用前13个字符。下面是函数的代码

  • 我将把choose/Others函数放在哪里?似乎有几个会重复,这让我很困惑
  • 如何捕获特定字符串中的“/”
  • 我会继续研究,并为没有列出尝试过的事情道歉,因为我甚至不知道从哪里开始

    <func:function name="func:getProjClaimNo">
          <xsl:param name='Proj' />
          <xsl:param name='Claim' />
    
          <xsl:variable name="isNUMB"       select="'1234567890'"/>
          <xsl:variable name="vProj1"        select="substring($Proj, 8, 1)"/>
          <xsl:variable name="vProj2"        select="substring($Proj, 9, 1)"/>
    
          <xsl:choose>  <!-- 1 -->
               <xsl:when test="contains($isNUMB,$vProj1)">                                                  <!-- 1 -->
                <xsl:choose>                                                                        <!-- 2 -->
                    <xsl:when test="contains($isNUMB,$vProj2)">                                         <!-- 2 -->
                        <xsl:variable name="vProj3"        select="number(substring($Proj, 8, 2))"/>
                        <xsl:choose>                                                                <!-- 3 -->
                            <xsl:when test="$vProj3 &gt; 8">                                            <!-- 3 -->
                                    <func:result select="$Proj"/>
                            </xsl:when>                                                         <!-- 3 -->
                            <xsl:otherwise>                                                     <!-- 3 -->
                                <!-- May need to check to see if claim number is empty or if proj in table -->
                                <xsl:choose>
                                                                                            <!-- 4 -->
                                    <xsl:when test="$Claim=''">                                     <!-- 4 -->
                                            <func:result select="substring($Claim, 1, 13)"/>
                                    </xsl:when>                                                 <!-- 4 -->
                                    <xsl:otherwise>                                             <!-- 4 -->
                                            <func:result select="substring($Claim, 1, 13)"/>
                                    </xsl:otherwise>                                                <!-- 4 -->
                                    </xsl:choose>                                                       <!-- 4 -->
                            </xsl:otherwise>                                                        <!-- 3 -->
                            </xsl:choose>                                                               <!-- 3 -->
                    </xsl:when>                                                                 <!-- 2 -->
                    <xsl:otherwise>                                                             <!-- 2 -->
                        <!-- May need to check to see if claim number is empty -->
                        <xsl:choose>                                                                <!-- 5 -->
                            <xsl:when test="$Claim=''">                                             <!-- 5 -->
                                    <func:result select="substring($Claim, 1, 13)"/>
                            </xsl:when>                                                         <!-- 5 -->
                            <xsl:otherwise>                                                     <!-- 5 -->
                                    <func:result select="substring($Claim, 1, 13)"/>
                            </xsl:otherwise>                                                        <!-- 5 -->
                            </xsl:choose>                                                               <!-- 5 -->
                    </xsl:otherwise>                                                                <!-- 2 -->
                </xsl:choose>                                                                       <!-- 2 -->
               </xsl:when>                                                                          <!-- 1 -->
               <xsl:otherwise>                                                                      <!-- 1 -->
                    <!-- May need to check to see if claim number is empty -->
                <xsl:choose>                                                                        <!-- 6 -->
                    <xsl:when test="$Claim=''">                                                     <!-- 6 -->
                            <func:result select="substring($Claim, 1, 13)"/>
                    </xsl:when>                                                                 <!-- 6 -->
                    <xsl:otherwise>                                                             <!-- 6 -->
                            <func:result select="substring($Claim, 1, 13)"/>
                    </xsl:otherwise>                                                                <!-- 6 -->
                    </xsl:choose>                                                                       <!-- 6 -->
               </xsl:otherwise>                                                                     <!-- 1 -->
          </xsl:choose>                                                                             <!-- 1 -->
     </func:function>
    
    
    
    我看不出“字段”在样式表片段中的位置。通常,您可以执行以下操作:

    <xsl:choose>
        <xsl:when test="substring($yourfield, 12, 1) ='/'">
            <xsl:value-of select="substring($yourfield, 1, 11)"/>   
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="substring($yourfield, 1, 13)"/>   
        </xsl:otherwise>
    </xsl:choose>
    
    
    
    或者更简洁地说:

    <xsl:value-of select="substring($yourfield, 1, 13-2*(substring($yourfield, 12, 1) ='/'))"/>
    
    
    
    但是,如果我理解正确,可能会简单得多:

    <xsl:value-of select="substring-before($yourfield, '/')"/>  
    

    最后一个简单有效……我非常感谢您的回复。我将测试所有场景并提供结果。非常感谢!!!!