2015-03-25 106 views
0

我選擇的名字,用數字開始從1到13:如何使用xslt中的通配符從字符串中提取數字?有

<description> 
</description> 
<short>1EN-1</short> 
</description> 
<description> 
<short>2EN-1</short> 
</description> 

,並以此類推,直到

<description> 
<short>13EN-1</short> 
</description> 

我需要能夠提取的第一個數字。

我已經使用以下代碼:

<xsl:when test="starts-with(description/short, '1')">1</xsl:when> 

不幸的是,這個字符串兩者的描述/短路開始與1和11,12和13的任何建議開始的那些返回1將不勝感激!

+0

是後面的字符串中的龍頭號碼(「EN」你的例子)事先知道?如果是的話,你可以簡單地使用'substring-before()'函數來提取數字。如果不是,下一個字符是什麼**是已知的?或者關於這個數字的最大尺寸? – 2015-03-25 10:32:45

+0

在' - '之前獲取子字符串,並使用雙重翻譯僅對數字進行過濾。 – 2015-03-25 10:35:12

回答

1

xsl:choose第一when測試匹配將是使用的人,所以在較短的前放的時間越長的前綴測試:

<xsl:choose> 
    <xsl:when test="starts-with(description/short, '13')">...</xsl:when> 
    <xsl:when test="starts-with(description/short, '12')">...</xsl:when> 
    <!-- ... --> 
    <xsl:when test="starts-with(description/short, '2')">...</xsl:when> 
    <xsl:when test="starts-with(description/short, '1')">...</xsl:when> 
</xsl:choose> 
+0

這樣做!謝謝! – 2015-03-25 12:00:17

+0

@JoachimHollekim請不要忘記接受這個答案,如果它解決了你的問題。謝謝! – 2015-03-25 14:50:51

相關問題