在xsl/xslt中基于特定索引获取子字符串

在xsl/xslt中基于特定索引获取子字符串,xslt,Xslt,我的xsl变量中有一个很长的web url。 如。 @url=”http://stackoverflow.com/questions/ask/2434/35454" 我需要一个基于第三个索引“/”的子字符串。i、 e我只想显示 xsl中有一个子字符串(string、start、length)函数,但如何查找长度部分。我找不到函数的任何索引 <xsl:value-of select="substring(url,1,length)"/> 我的网址是——”http://stac

我的xsl变量中有一个很长的web url。 如。 @url=”http://stackoverflow.com/questions/ask/2434/35454"

我需要一个基于第三个索引“/”的子字符串。i、 e我只想显示

xsl中有一个子字符串(string、start、length)函数,但如何查找长度部分。我找不到函数的任何索引

<xsl:value-of select="substring(url,1,length)"/> 

我的网址是——”http://stackoverflow.com/questions/ask/2434/35454" 我想要的输出是

请提出一些解决方案。

使用:

   concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">
  <xsl:value-of select=
  "concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
  "/>
 </xsl:template>
</xsl:stylesheet>
<t>http://stackoverflow.com/questions/ask/2434/35454</t>
http://stackoverflow.com
完整的代码示例

   concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">
  <xsl:value-of select=
  "concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
  "/>
 </xsl:template>
</xsl:stylesheet>
<t>http://stackoverflow.com/questions/ask/2434/35454</t>
http://stackoverflow.com
使用

   concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">
  <xsl:value-of select=
  "concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
  "/>
 </xsl:template>
</xsl:stylesheet>
<t>http://stackoverflow.com/questions/ask/2434/35454</t>
http://stackoverflow.com
完整的代码示例

   concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template match="/*">
  <xsl:value-of select=
  "concat(substring-before(.,'//'),
          '//',
          substring-before(substring-after(., '//'),
                           '/'
                           )
         )
  "/>
 </xsl:template>
</xsl:stylesheet>
<t>http://stackoverflow.com/questions/ask/2434/35454</t>
http://stackoverflow.com

因此,如果我的url存储在$url中,我必须这样使用。concat(在(url,“/”)、“/”、在(url,“/”)、“/”)之前的子字符串、在(url,“/”)之后的子字符串)@AbhiRoczz…是的,但是不要忘记变量名称之前的
$
字符。因此,如果我的url存储在$url中,我必须像这样使用。concat(前面的子字符串(url,“/”)、“/”、前面的子字符串(后面的子字符串)(url,“/”)、“/”)@AbhiRoczz…是的,但不要忘记变量名称前面的
$
字符。