我有XSLT代码的问题

时间:2013-11-13 14:05:45

标签: xml xslt

我在XSLT中遇到了一些问题。我需要写这样的东西:

$city1 = substring-after($address, ',')  
$city2 = substring-before($city1, ' -')  
$city = $city2 or $city1 if $city2 empty

我已经有了这个

<xsl:variable name="city1"   select = "substring-after($adress,',')" /> 
<xsl:variable name="city2"   select = "substring-before($city1,'-')" /> 
<xsl:variable name="city"   select = "normalize-space($city2 or $city1)" /> 

但最后一轮不起作用......我该如何解决?

1 个答案:

答案 0 :(得分:0)

试试这个

<xsl:variable name="city1" select = "normalize-space(substring-after($address,','))" /> 
<xsl:variable name="city2" select = "normalize-space(substring-before($city1,'-'))" /> 
<xsl:variable name="city">
  <xsl:choose>
    <xsl:when test="$city2 != ''">
       <xsl:value-of select="$city2"/>
    </xsl:when>
    <xsl:otherwise>
       <xsl:value-of select="$city1"/>
    </xsl:otherwise>
  </xsl:choose>
</xsl:variable>