Author |
Message
|
stebu |
Posted: Tue Oct 25, 2005 12:31 am Post subject: XSLT read from DB |
|
|
Newbie
Joined: 11 Oct 2004 Posts: 7 Location: Germany
|
hi
i'm working with the message broker toolkit version 5.0.2.
i want to transform a XML-Input-Message to a XML-Output-Message. the location of the xmltransformation (xslt) is db2.
IN-->COMPUTENODE(DB-ESQL)-->XMLTRANSFORMATION-->OUT
How can i read xslt from database and write it to a file.
importantly here:
- i dont' want to call a java-application to write the file.
- i want to set/generate the xslt path/file dynamic for every input-message.
i will be thankful for those with any ideas on how this can be done. |
|
Back to top |
|
 |
wschutz |
Posted: Tue Oct 25, 2005 2:09 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
The doc claims that you can imbed the XSLT into the message and set the XML Translation node to recognize this fact. Personally, i have'nt tried it (but maybe I will this morning). _________________ -wayne |
|
Back to top |
|
 |
stebu |
Posted: Tue Oct 25, 2005 2:54 am Post subject: |
|
|
Newbie
Joined: 11 Oct 2004 Posts: 7 Location: Germany
|
thanks for this quickly reply.
stebu |
|
Back to top |
|
 |
wschutz |
Posted: Tue Oct 25, 2005 7:30 am Post subject: |
|
|
 Jedi Knight
Joined: 02 Jun 2005 Posts: 3316 Location: IBM (retired)
|
I did this on this morning's train ride.... it works as advertised (of course)...
you can imbed the xsl:stylesheet into the xml message before sending it to the XMLTransformation node. For reference, here's the message (derived from the samples gallery):
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="#style1"?>
<Contact>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
id="style1"
xmlns:xalan="http://xml.apache.org/xslt">
<xsl:output method="xml" encoding="UTF-8" indent="yes" xalan:indent-amount="2"/>
<xsl:strip-space elements="*"/>
<!--======================================================================-->
<!-- This file contains an XSLT transformation stylesheet which -->
<!-- constructs a result tree from a number of XML sources by filtering -->
<!-- reordering and adding arbitrary structure. This file is -->
<!-- automatically generated by the XML Mapper tool from IBM WebSphere -->
<!-- Studio Workbench. -->
<!--======================================================================-->
<!--======================================================================-->
<!-- The Root Element -->
<!-- The "Root Element" section specifies which template will be -->
<!-- invoked first thus determining the root element of the result tree. -->
<!--======================================================================-->
<xsl:template match="/">
<xsl:call-template name="Member"/>
</xsl:template>
<!--======================================================================-->
<!-- Remaining Templates -->
<!-- The remaining section defines the template rules. The last template -->
<!-- rule is a generic identity transformation used for moving complete -->
<!-- tree fragments from an input source to the result tree. -->
<!--======================================================================-->
<!-- Newly-defined element template -->
<xsl:template name="Contact">
<Contact>
<LastName>
<xsl:value-of select="substring-after(/Contact/PostalAddress/DeliverTo/text(), ' ')"/>
</LastName>
<FirstName>
<xsl:value-of select="substring-before(/Contact/PostalAddress/DeliverTo/text(), ' ')"/>
</FirstName>
<xsl:for-each select="/Contact/Email">
<Email>
<xsl:value-of select="text()"/>
</Email>
</xsl:for-each>
</Contact>
</xsl:template>
<!-- Composed element template -->
<xsl:template match="PostalAddress">
<Address>
<AddressType>
<xsl:value-of select="preceding-sibling::Name/text()"/>
</AddressType>
<xsl:for-each select="Street">
<AddressLine1>
<xsl:value-of select="text()"/>
</AddressLine1>
</xsl:for-each>
<City>
<xsl:value-of select="City/text()"/>
</City>
<State>
<xsl:value-of select="State/text()"/>
</State>
<Zip>
<xsl:value-of select="PostalCode/text()"/>
</Zip>
<Country>
<xsl:value-of select="Country/text()"/>
</Country>
</Address>
</xsl:template>
<!-- Newly-defined element template -->
<xsl:template name="Member">
<Member>
<xsl:apply-templates select="/Contact/PostalAddress"/>
<xsl:call-template name="Contact"/>
</Member>
</xsl:template>
<!-- Identity transformation template -->
<xsl:template match="*|@*|comment()|processing-instruction()|text()">
<xsl:copy>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
<Name>Main Office</Name>
<PostalAddress>
<DeliverTo>David Lauzon</DeliverTo>
<Street>1150 Eglinton Ave</Street>
<Street>Station 4T</Street>
<City>Toronto</City>
<State>Ontario</State>
<PostalCode>M1C 5C2</PostalCode>
<Country>Canada</Country>
</PostalAddress>
<Email>david@ca.ibm.com</Email>
</Contact>
|
_________________ -wayne |
|
Back to top |
|
 |
stebu |
Posted: Tue Oct 25, 2005 11:00 pm Post subject: |
|
|
Newbie
Joined: 11 Oct 2004 Posts: 7 Location: Germany
|
thanks, that's exactly the solution of my problem
stebu |
|
Back to top |
|
 |
hascheidl |
Posted: Mon Jun 05, 2006 5:28 am Post subject: XSL in a file |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
In my case, I’d like to dynamically get the XSL, stored in a specific file, according to messages content. For example, if a message contains a PROVIDER_ID = 001, I want to use PROVIDER001.xsl. Is this possible?
Thanks in advance. _________________ Half |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jun 05, 2006 5:35 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
You will have to write something to read from a file. _________________ I am *not* the model of the modern major general. |
|
Back to top |
|
 |
hascheidl |
Posted: Mon Jun 05, 2006 6:03 am Post subject: |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
I am trying with the lines bellow, within a compute node before a xmltransformation node.
SET OutputLocalEnvironment.ComIbmXslOutputCharset = 1208;
SET OutputLocalEnvironment.ComIbmXslXmltStylesheetname = "c:\xslt\119mon.xsl";
I will see the results and let you know. Thanks. _________________ Half |
|
Back to top |
|
 |
hascheidl |
Posted: Mon Jun 05, 2006 10:03 am Post subject: `evaluate` exception |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
In order to pass information in OutputLocalEnvironment within the compute node, I had to change the node propertie "Compute Mode" to "Local Environment and Message". I didn't know this.
I`ve tried:
Code: |
SET OutputLocalEnvironment.Variables.ComIbmXslOutputCharset = 1208;
SET OutputLocalEnvironment.Variables.ComIbmXslXmltStylesheetname = 'c:\xslt\119mon.xsl';
|
and
Code: |
SET OutputLocalEnvironment.ComIbmXslOutputCharset = 1208;
SET OutputLocalEnvironment.ComIbmXslXmltStylesheetname = 'c:\xslt\119mon.xsl';
|
Both gave me the following exception:
Quote: |
The method 'evaluate' in Java node 'XMLTransformation' has thrown the following exception: java.lang.NullPointerException.
The method 'evaluate' of the Java plug-in node has thrown an exception. Examine previous error messages for details of the cause of the problem.
|
Do you have any suggestions about what should be the problem? Separate files are still the best approach to my problem here, that`s why i haven`t tried storing them in the DB. Thanks _________________ Half |
|
Back to top |
|
 |
jefflowrey |
Posted: Mon Jun 05, 2006 10:14 am Post subject: |
|
|
Grand Poobah
Joined: 16 Oct 2002 Posts: 19981
|
Passing a file path will not cause that file to be read.
You will have to write code that will read the file into memory, and then add embed the stylesheet into the message in the same way as if it was read from a database.
EDIT: Maybe I'm wrong. _________________ I am *not* the model of the modern major general.
Last edited by jefflowrey on Tue Jun 06, 2006 4:43 am; edited 2 times in total |
|
Back to top |
|
 |
XZ |
Posted: Tue Jun 06, 2006 12:19 am Post subject: |
|
|
 Apprentice
Joined: 22 May 2006 Posts: 45 Location: IBM Hursley
|
SET OutputLocalEnvironment.ComIbmXslXmltStylesheetname = 'c:\xslt\119mon.xsl';
should work in principal. Have you tried using double '\' ('\\')? Does your ComputteNode's Compute Mode include "LocalEnvironment"? Is your XMLT node style sheet selection priority properly set? Is there any other clue indicating why the null point exception occurred? _________________ Regards,
-XZ
WMQI Development |
|
Back to top |
|
 |
hascheidl |
Posted: Wed Jun 07, 2006 5:15 am Post subject: Error description |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
Quote: |
Does your ComputteNode's Compute Mode include "LocalEnvironment"? |
Yes.
Code: |
Compute node = Local Environment and Message |
Quote: |
Is your XMLT node style sheet selection priority properly set? |
Yes.
XML Embedded Sel. Priority = 2
Msg Env. Sel. Priority = 1
Broker Node Attribute Sel. Priority = 0
Quote: |
Is there any other clue indicating why the null point exception occurred? |
The exception tree includes "setOptionsFromPropertiesFolder".
Also, the XML that should be transformed is build dinamycally by a external procedure, with data from database. The message, before entering the XML transf. node, has the following structure (from debug):
Message
Properties
XML
xsl:stylesheet
(...)
ORDER
orderID
date
(...)
Any more guesses? _________________ Half |
|
Back to top |
|
 |
XZ |
Posted: Wed Jun 07, 2006 5:44 am Post subject: |
|
|
 Apprentice
Joined: 22 May 2006 Posts: 45 Location: IBM Hursley
|
Well, it seems that there is a problem with your message construction. The setOptionsFromPropertiesFolder tries to extract encoding and char set id info
from your message Properties folder. It looks like the Node could not find the Properties folder. Is the Properties folder built by the extaernal procedure as well? Do you have the same problem if your send a message which is known working? _________________ Regards,
-XZ
WMQI Development |
|
Back to top |
|
 |
hascheidl |
Posted: Wed Jun 07, 2006 5:46 am Post subject: |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
Sorry, I dont have a lot of experience with XML. How should I put the xsl stylesheet in the message?
Building it like
XML
--xsl:stylesheet
--ORDER
will throw an exception (two root elements)... _________________ Half |
|
Back to top |
|
 |
hascheidl |
Posted: Wed Jun 07, 2006 10:44 am Post subject: |
|
|
Novice
Joined: 05 Jun 2006 Posts: 15
|
XZ wrote: |
SET OutputLocalEnvironment.ComIbmXslXmltStylesheetname = 'c:\xslt\119mon.xsl';
should work in principal. Have you tried using double '\' ('\\')? |
Yes, it worked. I tried
Code: |
SET OutputLocalEnvironment.ComIbmXslXmltStylesheetname = '/xslt/119mon.xsl'; |
an it worked as well (Windows XP).
However, I am deploying in my own machine. Probably it works the same way if I deploy to another machine (assuming that I will put the xsl files in the same file path). Is that right?
It seems that this is not the best solution for me, because I will handle a lot of diferent XSL files, which won't be provided at the same time, and are also prone to maintainance. Also, this hard-coded file path seems to be a little risk... What do you think?
I think I will work a little more on how to get it from a DB...[/code] _________________ Half |
|
Back to top |
|
 |
|