Using transform api with xslt and DOM Nodes

Hi,
when trying to transform a xml document with xslt using the javax.xml.transform api
providing an element node of a previously parsed document, I find that absolute
paths are not recognized.
The following program shows what I am basically doing (the class can be executed
on the command line providing a stylesheet and xml instance):
import java.io.*;
import org.w3c.dom.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import javax.xml.parsers.*;
class Transform {
public static void main(String [] args) throws Exception {
     TransformerFactory tfactory = TransformerFactory.newInstance();
     Transformer transformer = tfactory.newTransformer(new StreamSource(args[0]));
     DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
     DocumentBuilder parser = dfactory.newDocumentBuilder();
     Document doc = parser.parse(args[1]);
     Element domElem = doc.getDocumentElement();
     // workaround
//     StringWriter out = new StringWriter();
//     Transformer id = tfactory.newTransformer();
//     id.transform(new DOMSource(domElem),new StreamResult(out));
//     String xml = out.toString();
//     transformer.transform(new StreamSource(new StringReader(xml)), new StreamResult(System.out));
     transformer.transform(new DOMSource(domElem), new StreamResult(System.out));
transformer.clearParameters();
If I use this on e.g.
xsl:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes" encoding="ISO-8859-1" method="xml"/>
<xsl:template match="/">
<xsl:value-of select="/foo/bar"/>
</xsl:template>
</xsl:stylesheet>
xml:
<foo>abc<bar>def</bar></foo>
I get
<?xml version="1.0" encoding="ISO-8859-1"?>
abcdef
instead of
<?xml version="1.0" encoding="ISO-8859-1"?>
def
I think this is due to the fact, that the transformation does not recognize
any absolutely adressed xpath correctly.
From what I read in the API docs, I think what I'm doing should be ok.
So: did I misunderstand something or is this a bug in the java libraries?
I'm using j2sdk 1.4.1_01 on i386 linux.
If I use the commented code (serializing the xml and doing the transformation
with a StreamSource, that has to be parsed again), everything's fine.
Of course it would be easier to parse the file directly in the example but in the
real program, I already have a dom tree and want to transform a part of it.
Any help appreciated.
Thanks, Morus

why?
that's all the point of XSL: define what part of your
XML you want in your XSL templates, there is no need
to prepare a sub-DOM of your DOM.
Ok. Right. That's an alternative.
The problem remains, that there are some stylesheets originally written
for the current solution and though they should work with the whole document
as well, it's not certain.
Actually I don't know if this ever worked. I did neither write this code nor maintained the system so far.
btw. you would be faster by giving a StreamSource to
your transformation.Probably yes. But that would imply to rewrite a lot of code.
What is happening is:
there is a SOAP answser containing a xml document as the result parameter.
The SOAP answer is parsed (I guess by the soap classes already) and the
result xml is extracted. That's where the element node I'm trying to transform
stems from.
Besides, I still don't see why DOMSource takes any node if only document nodes
work.
Thanks, Morus

Similar Messages

  • "XSL Error: Cannot use a DTMLiaison for a input DOM node"

    This code:
    Writer writer = new StringWriter();
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
    // Note: event.getDocument() returns a
    // org.apache.xerces.dom.DocumentImpl
    // sourced from xlms.jar
    processor.process(new XSLTInputSource(event.getDocument()),
    new XSLTInputSource(new FileReader(GDS_XSLT_STYLESHEET)),
    new XSLTResultTarget(writer));
    Gives this stacktrace:
    XSL Error: Cannot use a DTMLiaison for a input DOM node... pass a weblogic.apache.xalan.xpath.xdom.XercesLiaison
    instead!
    XSL Error: SAX Exception
    weblogic.apache.xalan.xslt.XSLProcessorException:
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1756)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1648)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.java:876)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:600)
    1. All XML/XSLT classes are being sourced from weblogic.jar or xmlx.jar
    2. Both jar files come from the WLS installation (WLS6.0 + SP2)
    3. There are no other XML class providers on my class path
    4. This is a standalone application, not running within WLS; I'm using weblogic
    jarfiles here purely so I use the same XML implementation both inside and outside
    WLS. Is this a sensible approach?
    Any help, anyone?

    All works fine in WLS6.1, with this extra code:
    System.setProperty("javax.xml.transform.TransformerFactory",
    "weblogic.apache.xalan.processor.TransformerFactoryImpl");
    (or you could use -D)
    No longer concerned; we've moved off WLS6.0
    "Simon Spruzen" <[email protected]> wrote:
    >
    Interestingly, expanding the code to (the very verbose):
    Document sourceDocument = event.getDocument();
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
    StringWriter source = new StringWriter();
    XMLSerializer sourceSerializer = new XMLSerializer(source, new OutputFormat(sourceDocument));
    sourceSerializer.asDOMSerializer();
    sourceSerializer.serialize(sourceDocument.getDocumentElement());
    StringWriter output = new StringWriter();
    processor.process(new XSLTInputSource(source.toString()),
    new XSLTInputSource(new FileReader(GDS_XSLT_STYLESHEET)),
    new XSLTResultTarget(output));
    (i.e. document -> string -> transform -> string)
    works just fine, but this code is far too long-winded for me to be happy
    with.
    (Note that one of XSLTInputSource's ctors does take a Node, so I'm assuming
    that
    it should be perfectly safe to pass a Document here)
    (Note also, that for various reasons at the moment, using JAXP's transformer
    factory
    is difficult for us)
    "Simon Spruzen" <[email protected]> wrote:
    This code:
    Writer writer = new StringWriter();
    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
    // Note: event.getDocument() returns a
    // org.apache.xerces.dom.DocumentImpl
    // sourced from xlms.jar
    processor.process(new XSLTInputSource(event.getDocument()),
    new XSLTInputSource(new FileReader(GDS_XSLT_STYLESHEET)),
    new XSLTResultTarget(writer));
    Gives this stacktrace:
    XSL Error: Cannot use a DTMLiaison for a input DOM node... pass a weblogic.apache.xalan.xpath.xdom.XercesLiaison
    instead!
    XSL Error: SAX Exception
    weblogic.apache.xalan.xslt.XSLProcessorException:
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1756)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.error(XSLTEngineImpl.java:1648)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.getSourceTreeFromInput(XSLTEngineImpl.java:876)
         at weblogic.apache.xalan.xslt.XSLTEngineImpl.process(XSLTEngineImpl.java:600)
    1. All XML/XSLT classes are being sourced from weblogic.jar or xmlx.jar
    2. Both jar files come from the WLS installation (WLS6.0 + SP2)
    3. There are no other XML class providers on my class path
    4. This is a standalone application, not running within WLS; I'm using
    weblogic
    jarfiles here purely so I use the same XML implementation both inside
    and outside
    WLS. Is this a sensible approach?
    Any help, anyone?

  • Using KM APIs with Anonymous user

    Dear SDNites,
    I have gone thorough one of the SAP notes on possible CM scenarios with anonymous users. It says the the supported scenarios are Search, browse and download.
    My question is that can we use KM apis in these areas with anonymous users?  I got some documentation on KM Indexmanagement APIs for searching with TREX, which requires authenticated user. I am wondering is there any way to use those APIs with anonymous user access.
    Thanks a lot in advance.
    Regards
    Pavan

    Hi Pavan,
    if you access the KM via Web Service you'll find parameters in each service to send username and password.
    If you browse the KM reposiroties via http you may need to do an authentication first. If your portal accepts basic authentication (as it does by default) you may call the KM explorer iView with some URL like:
    http://<username>:<password>@<hostname>.<domain>:<port>/<path to KM iView>
    If this does not work, maybe you need to use a client that supports basic authentication (digest). This may be e.g. the OpenSourcer library [HttpClient|http://hc.apache.org/] from the Apache project.
    See [RFC2617|http://www.faqs.org/rfcs/rfc2617.html] for more details on Basic Authentication and Basic Authentication (digest).
    If you have some more questions, please come back.
    Carsten

  • Can i use 2D API with out using JRE.

    hi,
    can i use 2d API with out using JRE 1.3 .
    please reply
    ravi

    Yes, it was (still is?) supported in Java 1.2 - but no
    earlier.How is it done.can u please give some sample code.
    Thanks and regards,
    Ravikumar

  • Printer is overprinting old jobs on top of new jobs.  Using a Mac with OSx and a HP photosmart for over a year.  this just started happening.

    Printer is overprinting old jobs on top of new jobs.  Using a Mac with OSx and a HP photosmart for over a year.  this just started happening.

    RReset printing system again and the restart in Safe Mode . This will clear some caches,to do this hold down the Shift key when you hear the startup tone until a progress bar appears, after it has fully booted restart normally and add the printer.

  • Using iPhone 4s with IOS5 and my Music icon has disappeared.  How do I get it back?  Please.

    Using iPhone 4s with IOS5 and my Music icon has disappeared.  Please help me to get it back.

    It should be in your applications folder.  Locate it; click and hold onto it then drag it back to where it was.

  • C++: Is it possible using callback function with ncacn_http and rpcproxy server ?

    I have a remote procedure and I can call it using http over rpc. I pass trough an rpc proxy server for arriving to my rpc server.
    But I cannot call a callback function to my client inside the server function.
    Is it possible using callback function with ncacn_http and rpcproxy server ?
    We are using IIS on windows server 2008 R2 and the server rpc and the client on the same PC with rpc rpoxy.
    If I use ncan_ip_tcp all works fine.
    Thanks
    Gianluca

    Hi,
    About the develop question please post to the MSDN forum.
    MSDN forum Developer Network
    http://social.msdn.microsoft.com/Forums/en-US/home?forum=WAVirtualMachinesVirtualNetwork&filter=alltypes&sort=lastpostdesc
    Thanks for your understanding and support.
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • I am from India using my iphone4 with Vodafone and  firmware version 5.0.1(9A405). I am unable to access 3G from my device as the CELLULAR DATA NETWORK option in the settings is missing. Any methods or options for fixing the same????

    I am from India using my iphone4 with Vodafone and  firmware version 5.0.1(9A405). I am unable to access 3G from my device as the CELLULAR DATA NETWORK option in the settings is missing. Any methods or options for fixing the same????

    I am from India using my iphone4 with Vodafone and  firmware version 5.0.1(9A405). I am unable to access 3G from my device as the CELLULAR DATA NETWORK option in the settings is missing. Any methods or options for fixing the same????

  • Frequent disconnect using peap wpa2 with aes and tkip

    I got frequent disconnect for the users on wireless using peap wpa2 with aes and tkip.
    My network is setup with :
    -Wireless controller 4404
    -ACS 4.0
    -28 access point 1131g
    -Peap authentication with active directory windows 2003
    -windows xp - mschap2 with aes- tkip
    when i check only aes on the wireless controller 4404 the network user are able work in a stable condition

    This might similar to the bug where Wireless phones dont associate if WPA2 is configured with both AES/TKIP. In this case try to upgrade the controller.

  • PC Used to work with XP and airport Extreme Basestation but not with Vista

    Please help, my PC Used to work with XP and airport Extreme Basestation but not now with Vista. I have a MacBook Pro connected and also a Mac Pro connected to the network on it and they still work, i have put the latest software on the PC and the firmware is up to date. The only thing i can see on the network on the PC is the basestation Hard Disk (shared also to the Macs) but i cannot connect with the password, i have tried everything in my knowledge, including formatting the machine and reinsatlling OS and changing security setting to no avail. Any ideas anyone?

    With regard to your printer problem - take a look at this discussion:
    http://discussions.apple.com/thread.jspa?messageID=6312413&tstart=0

  • Opening PDF in browser using Adobe API - with mark up and comment features

    Hey,  
    Here is the scenario :   Firstly, the user has to review the file (say pdf) before approving it. I would like to open the pdf file in the browser directly for reviewing. Also, I want to add some mark up (sticky notes, etc) and comment features while reviewing. Using these features, the user can pin point the mistakes directly in the file and revert the file for changes if any.  
    And as part of implementation, I would like to use Adobe java API to do the same. But I couldn't find any code snippets for using this API.  
    Any kind of help would be appreciated. Thanks in advance.

    This forum is only for discussions on the forums themselves. I would suggest that you start from the Acrobat forum,
    http://forums.adobe.com/community/acrobat

  • Using DB Adapter with XMLDB and CLOB

    Hi,
    with oracle xmldb i can store XMLs in lob or structured storage (s. Oracle® XML DB Developer's Guide 10g Release 2 (10.2) B14259-02).
    Now my question:
    If want to use a database adapter in the ESB to wake up several BPELs. Is there a functionality how i can transform such a clob into a XML where i can use XSLTs?
    The db adapter does only map each column to one xml-tag...
    If i try to use a table with xmltype the creation of a database adapter fails with:
    "some tables contain columns that are not recognized by the database adapter, so they will captured as strings:
    sys_nc_rowinfo$(sys.xmltype)
    change teh type of the above columns to that of the closest supported type...."
    Message was edited by:
    HEWizard

    Hi,
    To get it working you have to create an AQ-table with payload type xmltype. The xmltype payload data type is available on rdbms 10g and up. If you are on 9i or lower use raw data type. Create a queue inside the AQ-table. I'm not quite sure what's the best scenario for you to the queue with data, but I would imagine that you could create a database trigger on the table you're talking about and enqueue the xml-data (payload) to the AQ-table. Thus using the AQ-table as a staging table for the ESB system.
    Next, create an ESB system using an AQAdapter to dequeue the queue (like you did using a DBAdapter). The adapter can handle both single-user and multi-consumer queue's and all data types (raw, xmltype and object types).
    Messages are dequeued generally within a second after you commited the transaction.
    Kind regards,
    H

  • SSL: Connection reset by peer ; Failed to enable crypto error while calling the report using bing API with SOAP client

    Hi,
    I am trying to fetch report using bing API and making a SOAP call for fetching the data. I get the following error:
    [Warning] fopen(): SSL: Connection reset by peer [file] /var/www/sites/psmedia/perfectstormmedia/tools/class/msn_api.class.php [line] 780
    02-04-2015 10:17:41 (BST) : [Warning] fopen(): Failed to enable crypto [file] /var/www/sites/psmedia/perfectstormmedia/tools/class/msn_api.class.php [line] 780
    02-04-2015 10:17:41 (BST) : [Warning] fopen(https://download.api.bingads.microsoft.com/ReportDownload/Download.aspx?q=rzr63XFt5qJduddohoIRyOYAP%2f1%2ftsnhk8L%2bzBmUpdU2CQlcUB98RpY%2bbOaLFFGMqAC4IUUadC%2fNdNnJqeVCY%2f%2bpy6noVsVA%2fMJp47a3Xb1VjABfKhcdKy6vqpgEdcQg%2fQZ7QcEpZ3bEloJjUtGpDquFk53BnkeHEPVWZkDYcsQegRz%2fpG4t4w6gKCCRmhArd6osr6ZU9CMJ3lbxtGXjcQEMPvP2apNyr9P%2fc8niyfWA2aBcm1aEmOLX2KL3aRJ4rz9N7gG7uBslVZH%2b4rUjHdB7CMkbb%2fHyHwvPTqGPbPCHnicefr%2b%2fDP70hlkBEGfyOOswK67%2bl1zh7CyIv%2bcMlaDsuDX1HeFf4uORfD41H1z7):
    failed to open stream: operation failed [file] /var/www/sites/psmedia/perfectstormmedia/tools/class/msn_api.class.php [line] 780
    Whenever I execute my script. Can you please let me know what we can do to solve this issue. The version of PHP we are using is 5.3.3 with open ssl. 

    Hi Shobha,
    I can't confirm what version of PHP you are using, but to err on the side of caution please use the version specified in the sample/SDK:
    PHP 5.4.14 has been installed from PHP.
    Here is our code examples:
    https://msdn.microsoft.com/en-US/library/bing-ads-overview-getting-started-php-with-web-services.aspx
    Thanks,
    Itai

  • NoSuchMethodError with org.w3c.dom.Node.getTextNode()

    Hi,
    I got a trouble with this method. I developped my app with Eclipse and jdk 1.5.
    I used the endrosed mechanism for updating xalan and xerces in my jre.
    Everything works fine on my computer, but as I want to run my app on an other machine, I got this error.
    I put a copy of my jre on the other machine and I launch the app from this jre. It seems the endorsed jars are taken in account, but it still doesn't work.
    Thanks for your help.

    I found ths solution.
    In my jre was missing the endorsed Dom.jar, found at jaxp.dev.java.net. to overwrite org.w3c.dom standard classes.

  • Oracle ADF conformity with XHTML and DOM Level 2

    Dear all,
    I wonder if Oracle ADF 10g can produce documents that confirm with the XHTML and DOM Level 2 standards. I searched in Google but it is little hard to figure out

    Ok, but I taught that after importing myModel2 in myModel1, Jdeveloper realise a merge and it visualizes a unique package, even if it is splitted on two or more projects/models.
    So that, it seems to me this procedure is useful for importing jar file, but not for splitting a very big project in a lot of smaller projects, doesn't it?
    Thanks for your opinion
    Andrea

Maybe you are looking for

  • Satellite L670 - Hard Disk Dead after 8 months only

    Hi, this morning I had to retunr my laptop due to bad hard disk problem. After 8 months, it's dead already. The positive points are: I am still under warranty and second the toshiba software hilighted me on time, allowing me to back up my data before

  • Restarting your program?

    Hi, I get to the end of my window application and I want it to restart when you click on the button. I have the button set up so thats not a problem. But what is the code I need for restartng the application?

  • Idoc to file scenario( I dont want acknowledgements )

    Hi all, where i can disble the acknowledgements in idoc to file scenario. Kiran

  • How do I tell my client version?

    Due to the nature of our setup, client workstations do not get the Universal Installer installed with the client software (the admins do not want us to be able to install new software on our own). Without the UI, how can I tell which version of the c

  • TS2446 I can't open my app ID please help

    Ever time I try to download my app for music it say ID is disabled please help