xsl-list
[Top] [All Lists]

Re: [xsl] No Duplicate Contain() is Allowed?

2007-12-18 07:50:44
Thanks to those who helped!

Now all the results are coming back in proper manner!

Alice

Quoting "G. Ken Holman" <gkholman(_at_)CraneSoftwrights(_dot_)com>:

At 2007-12-16 22:37 -0500, Alice Wei wrote:
   For those of you who may know something about SQL or XQuery might
be able to help me out.

The issue is not related to either of those.

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.

This does not happen for me ... I get the same error as you quote
below on the first xsl:if regardless of whether or not the second
xsl:if is present.  And given what I see, I expect you to get the
error on both.

I show my transcript below.  And I created another stylesheet
"alice2.xsl" that counts the nodes you've addressed.

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() ("", "", ...)

The first argument to contains() must be a single item (element,
string, attribute, whatever), and the function acts on the string
value of that item.  If you supply more than one item, that is an
error.  And, indeed, in both cases you are supplying more than one
item.

My document is obviously well-formed, can anyone please give me some
suggestions on how to get rid of this error?

Your address does not look like what I think you want.

You have "//book/*" ... which finds all children addressed by all
books in the entire instance.  I see three elements named "book", the
first has two child elements, the second has one, and the third has
two, for a total of 5.

So, you are passing five strings to the contains() instruction, so
you are getting the error.

I think you might want what is in the third stylesheet "alice3.xsl"
if you want to test that *any* of the addressed elements have 'XML'
in their values.  This uses:

   test="book/*[contains(.,'XML')]"

 and

   test=".//topic[contains(.,'XML')]"

I hope this helps.

. . . . . . . . . . . Ken


T:\ftemp>type alice.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>

T:\ftemp>type alice.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xsd="http://www.w3.org/2001/XMLSchema";
                exclude-result-prefixes="xsd"
                version="2.0">

<xsl:output method="text"/>

<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>

</xsl:stylesheet>
T:\ftemp>call xslt2 alice.xml alice.xsl alice.out  2>&1
Error on line 10 of file:/T:/ftemp/alice.xsl:
  XPTY0004: A sequence of more than one item is not allowed as the
first argument of
  contains() ("XML", "Wiley", ...)
Transformation failed: Run-time errors were reported

T:\ftemp>type alice2.xsl
<?xml version="1.0" encoding="US-ASCII"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                xmlns:xsd="http://www.w3.org/2001/XMLSchema";
                exclude-result-prefixes="xsd"
                version="2.0">

<xsl:output method="text"/>

<xsl:template match="bookshelf">
  //book/*:  <xsl:value-of select="count(//book/*)"/>
  //topic/*: <xsl:value-of select="count(//topic/*)"/>
</xsl:template>

</xsl:stylesheet>
T:\ftemp>call xslt2 alice.xml alice2.xsl alice.out  2>&1

T:\ftemp>type alice.out

  //book/*:  5
  //topic/*: 0
T:\ftemp>call xslt2 alice.xml alice3.xsl alice.out  2>&1

T:\ftemp>type alice.out
Yes there is a book with a child with 'XML'
Yes there is a topic descendant with 'XML'

T:\ftemp>rem Done!


--
Comprehensive in-depth XSLT2/XSL-FO1.1 classes: Austin TX,Jan-2008
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman(_at_)CraneSoftwrights(_dot_)com
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



Alice Wei
MIS 2008
School of Library and Information Science
Indiana University Bloomington
ajwei(_at_)indiana(_dot_)edu
812-856-2659


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>