[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] using str:tokenize named template results


Subject: [xsl] using str:tokenize named template results
From: "vwiswell" <vwiswell@xxxxxxxxxxx>
Date: Fri, 28 Mar 2008 14:58:30 -0500

The str:tokenize template works beautifully (I am required to use xslt 1.0). I am using it to split the input from a multiple select box submitted from an html page thusly:

      <xsl:variable name="inValues">
        <xsl:call-template name="str:tokenize">
           <xsl:with-param name="string" select="$input" />
        </xsl:call-template>
     </xsl:variable>

I want to loop through the tokens checking for matches in my main input, an xml file. So I need nested for-each loops, the outer one looping through my tokens from str:tokenize and the inner one looping through <city>s in my doc.

The xml looks like this:

<sites>
  <site>
    <city>A City</city>
    <institution>Axxxxx Univ.</institution>
    <administers>to any student</administers>
    <schedule>2 times per month</schedule>
    <additional_costs>$15 admin. fee</additional_costs>
    <contact_information>(123) 123-1234</contact_information>
  </site>
  <site>
    <city>B City</city>
    <institution>Bxxxx College</institution>
    <administers/>
    <schedule/>
    <additional_costs/>
    <contact_information/>
  </site>
  <site>
    <city>C City</city>
    <institution>Cxxxxx College</institution>
    <administers>to any student</administers>
    <schedule>1 time per month</schedule>
    <additional_costs>$10 refundable deposit</additional_costs>
    <contact_information>(123) 123-1234</contact_information>
  </site>
  ...
</sites>

I'm not getting any output, so I think I have context issues, but I'm not sure how to fix it. I don't really understand the relationship between the str:tokenize results and my xml doc. It seems analogous to multiple input xml docs, but I'm not sure how to code it. This is what I have tried:

<xsl:template name="buildTable">
<xsl:param name="tokens"/>
<xsl:variable name="ns" select="msxsl:node-set($tokens)"/>
<xsl:for-each select="$ns/token">
<xsl:value-of select="text()" /><br /><!-- this works and proves the tokens are as expected -->
<xsl:for-each select="//city[text() = $ns/token/text()]">
<xsl:sort select="city"/>
<xsl:value-of select="text()" /><br /><!-- this produces no output -->
</xsl:for-each>
</xsl:for-each>
</xsl:template>


If I remove the token (outer) for-each, I get output, but only for the first token (obviously). The tokens get passed to this template just fine.

I'd really appreciate a nudge in the right direction. Thanks.


Current Thread
Keywords