2012-06-18 38 views
1

對於愚蠢的問題抱歉,但xsl 1.0中的字符串處理不是我的強項之一。 我正在尋找一種提取僞html標籤之間的字符串的方法。 EG。使用xsl從字符串中提取字符串

<xsl:variable name="test"> 
    This is a string <link>http://www.stackoverflow.com</link> and some more stuff here 
</xsl:variable> 

這個想法最終會包含2個其他變量。

VAR1 = http://www.stackoverflow.com 和 VAR2 =這是一個字符串,在這裏

一些更多的東西就像我說,對不起,這是一個暗淡的問題。謝謝。

回答

1

這裏是如何做到這一點

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<xsl:variable name="test"> 
    This is a string <link>http://www.stackoverflow.com</link> and some more stuff here 
</xsl:variable> 

<xsl:variable name="vTestNodeset" select="document('')/*/xsl:variable[@name='test']"/> 

<xsl:variable name="var1" select="string($vTestNodeset/link)"/> 

<xsl:variable name="var2"> 
    <xsl:copy-of select="$vTestNodeset/text()"/> 
</xsl:variable> 

<xsl:template match="/"> 
    "<xsl:value-of select="$var1"/>" 
============  
    "<xsl:value-of select="$var2"/>" 
============  
    "<xsl:value-of select="normalize-space($var2)"/>" 
</xsl:template> 
</xsl:stylesheet> 

當這種轉變是在任何XML文檔(未使用),想要的結果是產生應用:

 "http://www.stackoverflow.com" 
============  
    " 
    This is a string and some more stuff here 
" 
============  
    "This is a string and some more stuff here" 
+0

謝謝您。就是這份工作。 –

+0

@ user1001421:不客氣。 –