在 XSLT 中检索页面 URL 参数或页面 URL [英] Retrieve page URL params or page URL in XSLT

查看:25
本文介绍了在 XSLT 中检索页面 URL 参数或页面 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个具有 URL 结构的页面:http://www.abc.com/xyz?parama=1&paramb=2

  • 是否可以创建一个通用方法来获取 URL 可能的任何附加参数的值 (parama=1&paramb=2)

  • 是否可以像 javascript 的 location.href 那样以 XSL 格式获取页面的 URL?

解决方案

是否可以像javascript的location.href那样用XSL获取页面的URL?

不完全相同,但是可以,查询字符串可以作为参数传递.

<块引用>

是否可以创建泛型获取任何值的方法附加参数 URL 可能(参数=1&参数=2)

是的,可以执行标记化(使用 tokenize() 函数在 XSLT 2.0 或 XSLT 1.0 中使用 str-split-to-words**FXSL 1.x 的模板或自己编写的递归标记化模板.)

XSLT 1.0 解决方案:

</xsl:模板><xsl:template match="word"><xsl:value-of select="."/><xsl:text>&#xA;</xsl:text></xsl:模板></xsl:stylesheet>

当上述转换应用于任何 XML 文档(不会被使用)时,就会产生想要的结果:

parama=1参数=2anyParamName=AnyValue

注意 使用 FXSL 1.x str-split-to-words 模板和使用 EXSLT ext:node-set() 扩展函数.

XSLT 2.0 解决方案:

 </xsl:模板>

执行上述 XSLT 2.0 转换时,会产生正确的结果:

parama=1参数=2anyParamName=AnyValue

I have a page which has URL structure : http://www.abc.com/xyz?parama=1&paramb=2

  • Is is possible to create a generic method for getting the values of any additional params the URL maybe (parama=1&paramb=2)

  • Is is possible to get the URL of the page in XSL similar to javascript's location.href ?

解决方案

Is is possible to get the URL of the page in XSL similar to javascript's location.href ?

Not exactly in the same way, but yes, the query string can be passed as a parameter.

Is is possible to create a generic method for getting the values of any additional params the URL maybe (parama=1&paramb=2)

Yes, one can perform tokenization (with the tokenize() function in XSLT 2.0 or in XSLT 1.0 using the str-split-to-words template of **FXSL 1.x or a self-written recursive tokenization template.)

XSLT 1.0 solution:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:ext="http://exslt.org/common"
>

   <xsl:import href="strSplit-to-Words.xsl"/>

   <xsl:output indent="yes" omit-xml-declaration="yes"/>
     <xsl:param name="pQString" select=
     "'?parama=1&amp;paramb=2&amp;anyParamName=AnyValue'"
     />


    <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="'?&amp;'"/>
      </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>&#xA;</xsl:text>
    </xsl:template>
</xsl:stylesheet>

when the above transformation is applied on any XML document (will not be used), the wanted result is produced:

parama=1
paramb=2
anyParamName=AnyValue

Do note the use of the FXSL 1.x str-split-to-words template and the use of the EXSLT ext:node-set() extension function.

XSLT 2.0 solution:

 <xsl:param name="pQString" as="xs:string" select=
 "'?parama=1&amp;paramb=2&amp;anyParamName=AnyValue'"
 />

<xsl:template match="/">
  <xsl:value-of separator="&#xA;" select=
  "tokenize($pQString, '\?|&amp;')
  "/>
</xsl:template>

When the above XSLT 2.0 transformation is performed, it produces the correct result:

parama=1
paramb=2
anyParamName=AnyValue

这篇关于在 XSLT 中检索页面 URL 参数或页面 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆