Wrox Programmer Forums
| 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 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 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

 
Old November 17th, 2008, 01:06 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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
 
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!

 
Old November 17th, 2008, 04:20 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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
 
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?

 
Old November 17th, 2008, 05:00 PM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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
 
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?

 
Old November 19th, 2008, 11:26 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
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
 
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.





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





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