Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 12th, 2009, 11:58 AM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT excluding elements based on an external document

I want to count and loop through elements in the master document excluding id's referenced in an external xml file, I can read the external document fine its just excluding that list thats the issue.

<xsl:value-of select="count(/compositeReport/bookReport/bookList/book)"/> -

<xsl:variable name="FILE" select="document('bookExclusionList.xml')"/>

<xsl:value-of select="count($FILE//bookId)"/>

<xsl:value-of select="count(/compositeReport/bookReport/bookList/book[not(count(bookId = $FILE//bookId) &gt; 0)])"/>

The above doesn't work but it would be how i'd imagine it would. Im using XALAN and so are restricted to XSLT1.0 which is the problem. Is there a way of doing this?
Reply With Quote
  #2 (permalink)  
Old January 12th, 2009, 12:05 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Please show us relevant samples of the two XML documents.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #3 (permalink)  
Old January 12th, 2009, 12:15 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here's the various xmls, thanks

Exclusion List:
<?xml version="1.0" encoding="utf-8"?>
<bookExclusionList>
<bookId>102687</bookId>
<bookId>102696</bookId>
</bookExclusionList>

MainDoc (shrunk for readability):

<compositeReport>
<bookReport>
<bookList>
<book>
<bookId>102733</bookId>
<categoryList>
<category>Software</category>
</categoryList>
<synopsis>blah Blah</synopsis>
</book>
<book>
<bookId>103121</bookId>
<categoryList>
<category>fiction</category>
</categoryList>
<synopsis>Some Book thing</synopsis>
</book>
</bookList>
</bookReport>
</compositeReport>
Reply With Quote
  #4 (permalink)  
Old January 12th, 2009, 12:25 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

If you want to count the book elements in the main document which have bookIds not listed in the exclusion list then I think you need
Code:
<xsl:value-of 
   select="count(/compositeReport/bookReport/bookList/book[not(bookId = document('bookExclusionList.xml')/bookExclusionList/bookId)])"/>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
  #5 (permalink)  
Old January 12th, 2009, 12:40 PM
Authorized User
 
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Problem is i get the following if i try this

Exception in thread "main" java.lang.VerifyError: (class: bookReport$0, method: test signature: (IIIILorg/apache/xalan/xsltc/runtime/AbstractTranslet;Lorg/apache/xml/dtm/DTMAxisIterator;)Z) Incompatible type for getting or setting field

Incidently its also the same when i try and do it other ways similar to this.

Last edited by ashcarrot; January 12th, 2009 at 01:03 PM..
Reply With Quote
  #6 (permalink)  
Old January 12th, 2009, 01:05 PM
Friend of Wrox
Points: 6,676, Level: 34
Points: 6,676, Level: 34 Points: 6,676, Level: 34 Points: 6,676, Level: 34
Activity: 33%
Activity: 33% Activity: 33% Activity: 33%
 
Join Date: Nov 2007
Location: Germany
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I have tried the following stylesheet
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  version="1.0">
  
  <xsl:output method="text"/>
  
  <xsl:template match="/">
  <xsl:value-of 
   select="count(/compositeReport/bookReport/bookList/book[not(bookId = document('test2009011203.xml')/bookExclusionList/bookId)])"/>
  </xsl:template>

</xsl:stylesheet>
against the following two files:
Code:
<compositeReport>
<bookReport>
<bookList>
<book>
<bookId>102733</bookId>
<categoryList>
<category>Software</category>
</categoryList>
<synopsis>blah Blah</synopsis>
</book>
<book>
<bookId>103121</bookId>
<categoryList>
<category>fiction</category>
</categoryList>
<synopsis>Some Book thing</synopsis>
</book>
<book>
<bookId>102687</bookId>
<categoryList>
<category>Software</category>
</categoryList>
<synopsis>blah Blah</synopsis>
</book>
</bookList>
</bookReport>
</compositeReport>


<bookExclusionList>
<bookId>102687</bookId>
<bookId>102696</bookId>
</bookExclusionList>
with Saxon 6.5 and with Xalan java 2.7.1 from the command line and both output "2" as the correct result.
However when I try to use Xalan from the command line with the -xsltc flag then I get the error you describe. That looks like a bug in Xalan XSLTC as far as I can tell.
I think there is a Xalan user list where you might find more help with Xalan problems.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
accessing elements using document() function geoGregory3 XSLT 2 February 28th, 2008 07:39 PM
Excluding Elements based on a Predicate Condition tasmisr XSLT 3 February 27th, 2008 01:00 PM
Comparing elements in an XML document dlorenz XSLT 0 August 7th, 2007 05:28 PM
Calling external scripts from XSLT dextermagnific XSLT 2 June 25th, 2007 03:55 AM
convert elements based on place in document jefke XSLT 2 May 17th, 2004 05:32 AM



All times are GMT -4. The time now is 05:35 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.