鑑於以下XML輸入(注意轉義符號字符的):
<URL>https://sample.com?first=one&second=two&third=three</URL>
如下因素的樣式表:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<output>
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after(URL, '?')"/>
</xsl:call-template>
</output>
</xsl:template>
<xsl:template name="tokenize">
<xsl:param name="text"/>
<xsl:param name="delimiter" select="'&'"/>
<xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
<xsl:if test="$token">
<xsl:element name="{substring-before($token, '=')}">
<xsl:value-of select="substring-after($token, '=')"/>
</xsl:element>
</xsl:if>
<xsl:if test="contains($text, $delimiter)">
<!-- recursive call -->
<xsl:call-template name="tokenize">
<xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
將返回:
<?xml version="1.0" encoding="UTF-8"?>
<output>
<first>one</first>
<second>two</second>
<third>three</third>
</output>
請注意,這隻有在工作查詢字段名稱也是有效的XML元素名稱。
你可能得到了一個downvote,因爲你沒有顯示任何努力去做這個你自己。你來這裏需要的是一個需求而不是一個問題 - 我們在這裏解決你的代碼問題,而不是爲你做你的工作。看看「[*我怎麼問一個好問題?*](http://stackoverflow.com/help/how-to-ask)」的一些建議。 –
「*我會得到URL *」是什麼意思?您如何「獲取」並將其傳遞給XSLT樣式表? –
http://stackoverflow.com/help/someone-answers –