[xsl] passing a string as a node list

Subject: [xsl] passing a string as a node list
From: "Tim" <xsl@xxxxxxxxxxxxxx>
Date: 21 Jun 2001 15:15:07 -0000
Hello again,

It's past lunch and all the blood has gone to my stomach so....

I have a jsp page that receiveds a list of keywords separated by spaces 
or comma's.  I use the java object StringTokenize to make up a list of 
keywords in xmley type:


A xsl parameter/variable is then set with the keywords xml string.  The 
following snip uses the variable (some of you have some of this bit 
before:) to search detail element for all the keywords:

<xsl:template match="articles">
	keywords = <xsl:value-of select="$keywords"/>
	<xsl:variable name="klist" select="document($keywords)"/>
	<xsl:for-each select="article[contains
		<font size="-2">
			<xsl:value-of select="normalize-space(date)"/>
		<a target="_top">
			<xsl:attribute name="href">/singlearticle.jsp?
id=<xsl:value-of select="@ID"/></xsl:attribute>
			<xsl:value-of select="normalize-space(title)"/>
	      <xsl:if test="position() = last()">
			There were <xsl:value-of select="position
()"/>articles found.

If I use the $keywords variable directly, Xerces throws the exception 
saying "Can not convert #STRING to a NodeList" so I've been trying 
various methods of turning the string into the node list.

document() does not work because it needs a URL.  I thought about 
saving it to disk but that means only one instance of the JSP can be 
processed at-a-time unless some sort of complicated naming is thought 
of.   Xerces/Xalan does not seem to have a method to pass a string as a 
node list so I'm going to try converting the string to a StreamSource 
and then pass it as a parameter/variable.

Unless anyone who is clevererer than me out there (most of you) has 
some better ideas.

Thanks for your time,

 <article ID="article1">
  <date>Tue Jun 19 10:38:02 BST 2001</date> 
  <detail>Tim has bought a Land Rover, for better or for worse. There 
will be no more tellings-off from the Better Half about wet dogs in 
good car.</detail> 
  <title>Tim Buys a Land Rover</title> 
 <article ID="article2">
  <date>Tue Jun 19 10:44:28 BST 2001</date> 
  <detail>Nice car but nothing compaired to Tim's new Landy.</detail> 
  <title>Kirsten Buys a Vauxhall</title> 

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

Current Thread