2017-10-19 7 views
-1

誰かが私が間違っていることを教えてもらえますか? <xsl:value-of select="string-length(add:Destinations/add:DestinationName)" /> = Sacramento、CAの場合、私は可変領域が西であると予想しますが、私は東になります。XSLT選択しないでください

<xsl:variable name="charCount"> 
    <xsl:value-of select="string-length(add:Destinations/add:DestinationName)" /> 
</xsl:variable> 
<xsl:variable name="amendedCharCount"> 
    <xsl:value-of select="$charCount - 2"/> 
</xsl:variable> 
<xsl:variable name="state"> 
    <xsl:value-of select="substring(add:Destinations/add:DestinationName,$amendedCharCount)"/> 
</xsl:variable> 
<xsl:variable name="region"> 
    <xsl:choose> 
    <xsl:when test="$state='CA'">west</xsl:when> 
    <xsl:otherwise>east</xsl:otherwise> 
    </xsl:choose> 
</xsl:variable>  
<xsl:element name="OperationsRegion"> 
    <xsl:value-of select="$region"/> 
</xsl:element>  
+0

本当に入力XMLを質問に投稿してください。ありがとう。 –

答えて

0

XSLT/XPathでは、文字列内の文字の索引付けは、0ベースではなく1ベースです。だから、代わりに

<xsl:variable name="amendedCharCount"><xsl:value-of select="$charCount - 2"/></xsl:variable> 

これを行ってください....

<xsl:variable name="amendedCharCount"><xsl:value-of select="$charCount - 1"/></xsl:variable> 

またはより良いまだ、この操作を行う(実際には最後の3文字を取得します)これを行う....

<xsl:variable name="amendedCharCount" select="$charCount - 1"/> 

宛先がすべて同じフォーマットの場合は、3つの式を1つに簡略化することもできます。これは、宛先名にコンマが1つしかない場合に有効です。

<xsl:variable name="state" select="substring-after(add:Destinations/add:DestinationName, ', ')" /> 
+0

は完全に機能します。私がやっていたよりも簡単な解決策。本当にありがとう! – Bob

+0

また、なぜこれが機能していないのかについての説明に感謝します。私は今私の間違いを見る。 – Bob

関連する問題