Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 12th, 2009, 11:58 AM
Authorized User
 
Join Date: Jun 2003
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?
 
Old January 12th, 2009, 12:05 PM
Friend of Wrox
 
Join Date: Nov 2007
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
 
Old January 12th, 2009, 12:15 PM
Authorized User
 
Join Date: Jun 2003
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>
 
Old January 12th, 2009, 12:25 PM
Friend of Wrox
 
Join Date: Nov 2007
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
 
Old January 12th, 2009, 12:40 PM
Authorized User
 
Join Date: Jun 2003
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..
 
Old January 12th, 2009, 01:05 PM
Friend of Wrox
 
Join Date: Nov 2007
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





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





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.