Re: [xsl] construct query string

Subject: Re: [xsl] construct query string
From: Joerg Heinicke <joerg.heinicke@xxxxxx>
Date: Tue, 07 May 2002 22:20:51 +0200
<root>
  <param1>blah</param1>
  <param2>blah</param2>
  <param3>blah</param3>
</root>

<xsl:template match="root">
  <xsl:variable name="query-string">
    <xsl:text>?</xsl:text>
    <xsl:for-each select="*">
      <xsl:value-of select="name()"/>
      <xsl:text>=</xsl:text>
      <xsl:value-of select="."/>
      <xsl:if test="position()!=last()">
        <xsl:text>&amp;</xsl:text>
      </xsl:if>
    </xsl:for-each>
  </xsl:variable>

  <xsl:text>variable $query-string: </xsl:text>
  <xsl:value-of select="$query-string"/>
</xsl:template>

Regards,

Joerg

Zack Angelo schrieb:
I'm attempting to construct a query string ("?param1=blah&param2=blah2",
for example) using the values of a series of tags in an XML document. My
first intuition was to create an XSL variable, and then send the
transformer into a loop which concats each param tag onto that variable.
However, after reading the W3C doc, it doesn't seem like that's feasible
because you can't "shadow" a XSLT variable in the same template context,
and you can't reference the variable you're trying to declare in the
variable definition.  TIA.

-Zack


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


Current Thread