我知道这是一个已经多次传递的老问题,但我想知道是否有人可以扩展一个带有查询字符串的 URL 是否可以通过 XSLT 1.0 剥离并且可以用作以后的参数使用 XSLT 转换。
例如,我有一个 URL 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) 已从查询字符串中提取以允许我使用$param1
,$param2
然后在 if 条件下说
例如<xsl:if test="$param1 = 'a'>
,结果为真,但如果我们使用<xsl:if test="$param1 = 'b'>
结果为假。
我在这里看到了一个类似的问题:Retrieve page URL params or page URL in XSLT which uses the str-split-to-words
template 但我没有成功地让它工作(可能是因为我以错误的方式实现它)所以任何关于它的工作示例可以在实践将大有裨益。
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>