Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0
This is the forum to discuss the Wrox book XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition by Michael Kay; ISBN: 9780470192740
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 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 November 17th, 2008, 12:29 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default xsl:copy-of Issue

I am having some trouble using xsl:copy-of and I am hoping you good folks would be able to help me. First, some background information on what I am attempting. I am trying to grab a node set from the XML file I am working with and pass it over to a Java function for processing in a XSL-FO processor. What it looks like is happening is when I pass the value it comes out as a string (as if I were using xsl:value-of instead of xsl:copy-of). I know this because when I set the parameter in Java to String, I get values (string content like xsl:value-of), but when I change the parameter data type to a NodeList it tells me the table is null. I am not sure what I am doing wrong here. Here is a clip of the code:


<xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:templateId/@root='2.16.840.1.113883.10.20.1.11']/n1:text/n1:table" >

  <fo:block>
      <xsl:copy-of select="javaRef:parseXMLtoDom(.)" />
  </fo:block>
</xsl:for-each>

Any ideas? Thanks!

David J. Katz

Reply With Quote
  #2 (permalink)  
Old November 17th, 2008, 01:06 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The behaviour of extension functions in XSLT is entirely implementation-defined, so you first need to tell us which XSLT processor you are using (I guess it's Xalan or Saxon, since the other three Java processors seem to be pretty-well defunct nowadays). It would also be useful to see your Java code.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #3 (permalink)  
Old November 17th, 2008, 02:40 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using Xalan 2.7.0. For the time being, I am just passing in the value and trying to display the result on the console before moving into the next steps of the program. Below is the code I am using if I am trying to display the resulting value as a string (which gives me string values without their tags):

 public void parseXMLtoDom (String xmlTextNode)throws Exception
    {
     System.out.println(xmlTextNode.toString());
    }

The following code will compile, but I get a "table:[null]" on the console when I try to display the first node in the index. This leads me to believe that XML is not being passed into the Java method:

 public void parseXMLtoDom (NodeList xmlTextNode)throws Exception
    {
         System.out.println(xmlTextNode.item(0));
    }

Thank you for the assistance!

Reply With Quote
  #4 (permalink)  
Old November 17th, 2008, 04:20 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I don't actually know how Xalan handles a Java method whose result type is declared as void, but since you are calling a method that doesn't return anything, and then trying to copy what it returns, I wouldn't expect anything very useful to happen as a result.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #5 (permalink)  
Old November 17th, 2008, 04:48 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It is true that the method is not yet returning a value, but I am able to pass in String values from the XSL and display them on the console via System.out.println, so it is doing something. Let me back this problem out a step. I tried thr following XSL code and found that "Hello World" displayed, but nothing else.


<xsl:for-each select="/n1:ClinicalDocument/n1:component/n1:structuredBody/n1:component/n1:section[n1:templateId/@root='2.16.840.1.113883.10.20.1.11']/n1:text/n1:table" >

<fo:block>
    <xsl:copy-of select="." />
    <xsl:text>Hello World!</xsl:text>
 </fo:block>

</xsl:for-each>

Just to make sure the FO processor was not the culprit, I ran this same XSL code (sans the FO tags) and came up with the same result. Any ideas?

Reply With Quote
  #6 (permalink)  
Old November 17th, 2008, 05:00 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>I tried thr following XSL code and found that "Hello World" displayed, but nothing else.

Difficult without seeing your source document (and since it looks like HL7 I would really rather not see it, it would spoil my evening). On the surface, the xsl:for-each has selected an element, the xsl:copy-of must therefore copy the element. So I think it has to be the conclusion: the bug is not in the code you have shown us, so it must be somewhere else. Your next step is to put together a demonstration of the problem that is complete enough for anyone to run, but concise enough to make that a practical proposition. At least you've now eliminated the extension function call as irrelevant to the problem.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #7 (permalink)  
Old November 18th, 2008, 12:42 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Here is a simple example where I'm taking Java and Xalan out of the picture. I am using XML Notepad to do the transformation. Here is the XML:

     <AAA >
          <BBB ooo = "111" ppp = "222" >
               <CCC>c1 </CCC>
               <CCC>c2 </CCC>
           </BBB>
          <BBB ooo = "555" ppp = "666" >
               <DDD>d1 </DDD>
               <DDD>d2 </DDD>
           </BBB>
      </AAA>

XSL:

<xsl:stylesheet xmlns:xsl = "http://www.w3.org/1999/XSL/Transform" version = "1.0" >

<xsl:output method = "xml" indent = "yes" />

    <xsl:template match = "/" >

         <xsl:copy-of select = "//BBB" />

    </xsl:template>
</xsl:stylesheet>

I am expecting to see the node-set displayed (starting at BBB), but instead in the transformation window I get: c1 c2 d1 d2. This is the result I would expect using xsl:value-of. This is as simple as it gets, so I am wondering if perhaps I am not understanding what this function should be doing?

Reply With Quote
  #8 (permalink)  
Old November 19th, 2008, 11:26 AM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I suspect you are viewing the result in a "browser" view, where it is treating the result tree as HTML. You need to look at it in an "XML" view, where you can see the markup. It's a while since I used XML Notepad and it's not installed on my current machine, but I'm sure it has option settings for how the output is viewed.

Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer's Reference
Reply With Quote
  #9 (permalink)  
Old November 19th, 2008, 05:18 PM
Registered User
 
Join Date: Nov 2008
Location: , , .
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I was able to get this working but I had to do a little home work with Xalan. I added

xmlns:HitMerExtractFoReport="xalan://src.HitMerExtractFoReport"

to the XSL header and changed the function to

<xsl:variable name="success" select="HitMerExtractFoReport:parseXMLtoDom(*)"/>

This passed the node set into Java as a NodeList/NodeSet/NodeIterator. Not my first choice of classes to work with when it comes to HL7 v3, but it will have to do. Thank you for the input.

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
How can i use xsl:copy-of in xsl sampath.bandaru XSLT 11 October 1st, 2008 03:37 AM
XSL Issue mickhughes XSLT 4 October 18th, 2007 08:29 AM
Copy one node to another in XSL hugoscp XML 5 September 14th, 2006 09:40 AM
Slightly modified xsl:copy-of arcuza XSLT 6 April 10th, 2006 04:53 AM
xsl:copy copies everywhere ravik@olemiss.edu XSLT 1 November 11th, 2005 07:44 AM



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


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