This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

passing a string as a node list


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:

<keywords>
 <keyword>
  find
 </keyword>
 <keyword>
  me
 </keyword>
<keywords>

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:

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

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,
Tim.

articles.xml
__________________
<articles>
 <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>
 <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> 
 </article>
</articles>


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]