[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

passing a string as a node list

Subject: passing a string as a node list
From: "Tim" <xsl@xxxxxxxxxxxxxx>
Date: 21 Jun 2001 15:15:07 -0000
kirsten buys
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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.