【发布时间】:2012-05-17 20:18:01
【问题描述】:
我知道这是一个老问题,已经传了好几次了,但我想知道是否有人可以扩展一个带有查询字符串的 URL 是否可以通过 XSLT 1.0 剥离并且可以用作供以后使用 XSLT 转换的参数。
例如,我的网址是http://www.mydomain.com/mypage.htm?param1=a¶m2=b
通过 XSLT,我正在寻找类似以下内容的结果:
<xsl:param name="param1">a</xsl:param> 和<xsl:param name="param2">b</xsl:param>
参数名称 (param1, param2) 和它的值 (a, b) 都已从查询字符串中提取出来,以便我稍后在 if 条件中使用 $param1 和 $param2
例如<xsl:if test="$param1 = 'a'> 为真,但如果我们使用 <xsl:if test="$param1 = 'b'> 则为假。
我在这里看到了一个类似的问题:Retrieve page URL params or page URL in XSLT 它使用了str-split-to-words 模板,但我没有成功地让它工作(可能是因为我以错误的方式实现它)所以任何关于如何完成它的工作示例实践将大有裨益。
XSLT:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/xhtml" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ext="http://exslt.org/common">
<xsl:import href="http://fxsl.cvs.sourceforge.net/viewvc/fxsl/fxsl-xslt2/f/strSplit-to-Words.xsl"/>
<xsl:output indent="yes" method="html"/>
<xsl:template match="/">
<xsl:variable name="vwordNodes">
<xsl:call-template name="str-split-to-words">
<xsl:with-param name="pStr" select="$pQString"/>
<xsl:with-param name="pDelimiters" select="'?&'"/>
</xsl:call-template>
</xsl:variable>
<xsl:apply-templates select="ext:node-set($vwordNodes)/*"/>
</xsl:template>
<xsl:template match="word">
<xsl:value-of select="."/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: