1

ばかげた質問で申し訳ありませんが、xsl1.0での文字列処理は私の強みの1つではありません。疑似htmlタグの間にある文字列を抽出する方法を探しています。例えば。

<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=これは文字列であり、ここにいくつかのものがあります

私が言うように、申し訳ありませんが、それは薄暗い質問です。ありがとう。

4

1 に答える 1

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"
于 2012-06-18T12:33:19.660 に答える