2012-03-27 28 views
1

有没有办法将一个属性,变量组合直接导入到带有xsl的url路径中?xsl:将变量传入xsl文件路径

实施例:

http://something.xsl?asdf=12&attribute2=1234 

我想用这些属性和值,以使XSL文件内某些标志。

回答

0

使用concat()

<xsl:variable name="url" select="concat($currURL, 'flag=true')" /> 
0

呀,你只需要逃避&&amp;

0

我想你的意思是可以将样式表访问自己的URI来访问参数。在XSLT2中,您可以使用static-base-uri()函数来访问URI,然后您可以将其拆分,以使用正则表达式字符串函数提取查询参数。在XSLT1中,这是不可能的,您需要以样式表参数传递信息,而XSLT1样式表无法访问源或其自身的URI。

0

下面是一个完整XSLT 1.0溶液中,假定URL被作为外部参数来变换通过:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xmlns:ext="http://exslt.org/common" exclude-result-prefixes="ext"> 
<xsl:output omit-xml-declaration="yes" indent="yes"/> 

<xsl:param name="pUrl" select= 
"'http://something.xsl?asdf=12&amp;attribute2=1234'"/> 

<xsl:template match="/"> 
    <xsl:variable name="vQuery" select="substring-after($pUrl, '?')"/> 

    <xsl:variable name="vrtfQueryItems"> 
    <xsl:call-template name="buildQueryItems"> 
    <xsl:with-param name="pQuery" select="$vQuery"/> 
    </xsl:call-template> 
    </xsl:variable> 

    <xsl:variable name="vQueryItems" 
    select="ext:node-set($vrtfQueryItems)/*"/> 

    <xsl:copy-of select="$vQueryItems"/> 
</xsl:template> 

<xsl:template name="buildQueryItems"> 
    <xsl:param name="pQuery"/> 

    <xsl:if test= 
    "string-length($pQuery) > 0"> 

    <xsl:variable name="vQuery" select="concat($pQuery, '&amp;')"/> 
    <xsl:variable name="vItem" select="substring-before($vQuery, '&amp;')"/> 

    <param name="{substring-before(concat($vItem, '='), '=')}"> 
    <xsl:value-of select="substring-after($vItem, '=')"/> 
    </param> 


    <xsl:call-template name="buildQueryItems"> 
    <xsl:with-param name="pQuery" select="substring-after($pQuery, '&amp;')"/> 
    </xsl:call-template> 
    </xsl:if> 
</xsl:template> 
</xsl:stylesheet> 

当这种转化是在任何XML文档(未使用)施加产生想要的结果

<param name="asdf">12</param> 
<param name="attribute2">1234</param>