/ / XSL, jeśli kolumna X jest znakiem X, zrób to inaczej - xslt

XSL, jeśli kolumna X jest znakiem X, zrób to jeszcze - xslt

-XSL wersja 1.0 -

Mam plik XSL, który został utworzony przez kogośże już nie działa w mojej firmie i oczywiście musimy zmienić XSL. Nigdy nie korzystałem z XSL, ale szukałem i wierzę, że mogę wykonać potrzebną funkcję, aktualizując XSL za pomocą funkcji wyboru.

-Kwestia- Mamy pole, które zostało zmienione z prowadzącegoliczba znaków od 13 do 11, ale musimy uchwycić oba przez pewien okres czasu. Zdecydowano o przycięciu dwóch wiodących postaci roku. Wartości pozostaną stałe aż do ukośnika „/” przy 13 lub 11 znakach, kolejne znaki mogą różnić się od 5-13 znaków.

  • 13 znaków CTM08G2012001 / 0001
  • 11 znaków CTM08G12001 / 0001

Chcę sprawdzić, czy 12. znak to „/” i czy używa pierwszych 11 znaków, a jeśli nie jest to pierwsze 13 znaków. Oto kod funkcji.

  1. Gdzie miałbym umieścić funkcję wyboru / w inny sposób? Wydaje się, że kilka się powtarza i to mnie myli.
  2. Jak przechwycić „/” w określonym ciągu?

Będę kontynuował badania i przepraszam, że nie mam listy rzeczy, które wypróbowałem, ponieważ nie jestem pewien od czego zacząć.

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

Odpowiedzi:

0 dla odpowiedzi № 1

Nie widzę, gdzie to „pole” znajduje się we fragmencie arkusza stylów. Ogólnie możesz zrobić coś takiego:

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

lub, bardziej zwięźle:

<xsl:value-of select="substring($yourfield, 1, 13-2*(substring($yourfield, 12, 1) ="/"))"/>

Jeśli jednak dobrze rozumiem, może być o wiele prostsze:

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