如何在我的xml文件中断开此文本“?#sid52985020”并添加到最后

时间:2016-07-14 04:25:00

标签: html xml xslt

如何在我的xml文件中删除此文本“?#sid52985020”并添加到最后

这是我的代码:

<xsl:variable name="gatracker1">?intenttarget=no&amp;</xsl:variable>

<a target="_blank"">
<xsl:attribute name="href"><xsl:value-of select="alink"/><xsl:value-of select="$gatracker1"/></xsl:attribute>
</a>

XML代码:

<alink>http://www.rohitazad.com/tax-return/newslist/51507984.cms?#sid52985020 </alink>

我想这样结果

"http://rohitazad.com/tax-return/newslist/51507984.cms?intenttarget=no&amp#sid52985020"

1 个答案:

答案 0 :(得分:1)

尝试类似:

<xsl:variable name="gatracker1">?intenttarget=no&amp;</xsl:variable>

<xsl:template match="alink">
    <a target="_blank">
        <xsl:attribute name="href">
            <xsl:value-of select="substring-before(., '?#')"/>
            <xsl:value-of select="$gatracker1"/>
            <xsl:value-of select="substring-after(., '?#')"/>
        </xsl:attribute>
    </a>
</xsl:template>

这假设您要在给定链接中第一个?#的位置插入变量。

请注意,您的结果为http://rohitazad.com/,但在源中为http://www.rohitazad.com