如何在XSLT中从url动态获取值
我有一个C类型的url:/Documents and Settings/Saxon/output1/index.html?value=65abc 现在,我需要从xslt中的url“65abc”获取这部分内容。当我点击一个链接时,我从上一页得到这个值 知道怎么做吗?使用:如何在XSLT中从url动态获取值,url,xslt,Url,Xslt,我有一个C类型的url:/Documents and Settings/Saxon/output1/index.html?value=65abc 现在,我需要从xslt中的url“65abc”获取这部分内容。当我点击一个链接时,我从上一页得到这个值 知道怎么做吗?使用: substring-after($pPath, '=') substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
其中,$pPath
是对全局外部xsl:param
的引用,该引用包含从转换调用程序传递的类似url的文件路径的值
如果pPath
包含多个查询字符串参数,并且您希望访问第一个参数的值,则使用:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
若您使用的是XSLT 2.0(XPath 2.0),则可以使用访问名为$pQName
的查询字符串参数的值:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
以下是完整的代码示例:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
其中,$pPath
是对全局外部xsl:param
的引用,该引用包含从转换调用程序传递的类似url的文件路径的值
如果pPath
包含多个查询字符串参数,并且您希望访问第一个参数的值,则使用:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
若您使用的是XSLT 2.0(XPath 2.0),则可以使用访问名为$pQName
的查询字符串参数的值:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
以下是完整的代码示例:
substring-after($pPath, '=')
substring-after(substring-before(substring-after($pPath, '?'), '&'), '=')
substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)
65abc
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="pPath" select=
"'C:/Documents and Settings/Saxon/output1/index.html?value=65abc&x=1&y=2'"/>
<xsl:param name="pQName" select="'x'"/>
<xsl:template match="node()|@*">
<xsl:sequence select=
"substring-after
(tokenize(substring-after($pPath, '?'), '&')
[starts-with(., concat($pQName, '='))],
'='
)"/>
</xsl:template>
</xsl:stylesheet>
1
XSL本身无法访问URL变量-您需要手动传入这些变量。您在哪个平台上运行XSL?例如,在PHP中,可以使用
$process->setParameter
。然后,只要您的XSL声明了变量,它就会收到它,您就可以引用它。谢谢您的回复!我正在使用XSLT进行XML到HTML的转换。我想有2个html文件,我正在使用萨克森。在第一个文件中,我有链接,当我点击链接时,一个值被发送到url。为此,我正在使用-现在当我单击链接时,我可以在url中获取值,现在我需要在XSLT中使用url中的值来显示其他详细信息。这不是url,而是Windows文件名。但仍然需要如何从中获取值。如果我在我的系统上运行文件,我仍然不清楚你在什么平台上做这些。如果是Saxon,您使用的是Java还是.NET?或者你的意思是你正在通过JavaScript进行XSL?无论是哪一个,您都需要检索URL变量,然后手动将它们传递到XSL(对于JavaScript,这并不总是可能的,具体取决于浏览器)。XSL本身通常无法访问URL变量-它们必须传入。XSL本身无法访问URL变量-您需要手动传入这些变量。您在哪个平台上运行XSL?例如,在PHP中,可以使用$process->setParameter
。然后,只要您的XSL声明了变量,它就会收到它,您就可以引用它。谢谢您的回复!我正在使用XSLT进行XML到HTML的转换。我想有2个html文件,我正在使用萨克森。在第一个文件中,我有链接,当我点击链接时,一个值被发送到url。为此,我正在使用-现在当我单击链接时,我可以在url中获取值,现在我需要在XSLT中使用url中的值来显示其他详细信息。这不是url,而是Windows文件名。但仍然需要如何从中获取值。如果我在我的系统上运行文件,我仍然不清楚你在什么平台上做这些。如果是Saxon,您使用的是Java还是.NET?或者你的意思是你正在通过JavaScript进行XSL?无论是哪一个,您都需要检索URL变量,然后手动将它们传递到XSL(对于JavaScript,这并不总是可能的,具体取决于浏览器)。XSL本身通常无法访问URL变量-它们必须传入。我仍然不清楚在这种情况下如何处理-C:/Documents and Settings/Saxon/output1/index.html?value=65abc。我只需要url中的“65abc”部分path@user1402867:难道你不知道如何使用
?我知道如何使用我做过类似的事情-output1/output3/index.html?当我使用并运行它时,它的值。我没有得到任何输出。@user1402867:我已经用完整的代码示例更新了这个答案。@user1402867:我已经做了一系列编辑,使代码具有格式和可读性。我仍然不清楚在这种情况下如何处理-C:/Documents and Settings/Saxon/output1/index.html?value=65abc。我只需要url中的“65abc”部分path@user1402867:难道你不知道如何使用
?我知道如何使用我做过类似的事情-output1/output3/index.html?当我使用并运行它时,它的值。我没有得到任何输出。@user1402867:我已用完整的代码示例更新了此答案。@user1402867:我已进行了一系列编辑,以使代码具有格式和可读性。