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

RE: No Duplicate Contain() is Allowed?

Subject: RE: No Duplicate Contain() is Allowed?
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 17 Dec 2007 09:39:38 -0000
RE:  No Duplicate Contain() is Allowed?
Read the spec for the contains() function - it doesn't do what you think.
You have guessed wrongly that it takes as input a set of nodes and returns
true if any of those nodes is equal to the second argument. What it actually
does is to take a single string as input and return true if that string
contains a specified substring.

Also, read the error message. It tells you very explicitly what you have
done wrong: contains requires a single item as the value of the first
argument, and you have supplied a sequence of values. If your XML had been
ill-formed, the message would have been completely different.

If you want to test whether any topic is equal to XML, use <xsl:if
test="//topic[. = 'XML']"/>. If you want to test whether any topic has "XML"
as a substring, use <xsl:if test="//topic[contains(., 'XML')"/>. 

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Alice Wei [mailto:ajwei@xxxxxxxxxxx] 
> Sent: 17 December 2007 03:38
> To: xsl-list
> Subject:  No Duplicate Contain() is Allowed?
> 
> Dear all:
> 
>     For those of you who may know something about SQL or 
> XQuery might be able to help me out.
> 
> XML:
>       <bookshelf>
>       <book>XSLT 2.0: From Beginning to Professional
>         <topic>XML</topic>
>        <publisher>Wiley</publisher></book>
>       <book>XML in a Nutshell
>       <publisher>Oreilly</publisher</book>
>       <book>XSLT 2.0: Programmer's Reference
>       <topic>XML</topic>
>       <publisher>Wrox</publisher>
>       </book>
>       </bookshelf>
> 
> XSLT:
> 
> <xsl:template match="bookshelf">
> 
>         <xsl:if test="contains(//book/*, 'XML')">
>             <xsl:apply-templates/>
>         </xsl:if>
>        <xsl:if test="contains(//topic/*, 'XML')">
>           <xsl:apply-templates/>
>       </xsl:if>
> </xsl:template>
> 
> 
> What happened is really weird. If I had commented out the 2nd 
> <xsl:if> statement, it brings back one line without error. 
> When I got to the 2nd one, it tells me this error: 
> Description: A sequence of more than one item is not allowed 
> as the first argument of contains() ("", "", ...)
> 
> My document is obviously well-formed, can anyone please give 
> me some suggestions on how to get rid of this error?
> 
> Thanks to those who can help.
> 
> Alice
> 
> 
> Alice Wei
> MIS 2008
> School of Library and Information Science Indiana University 
> Bloomington

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.