|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
WMB 8 - xsl transformation node skipping CDATA section |
« View previous topic :: View next topic » |
Author |
Message
|
szfamman |
Posted: Fri Jan 23, 2015 1:58 am Post subject: WMB 8 - xsl transformation node skipping CDATA section |
|
|
Newbie
Joined: 07 Jul 2014 Posts: 9
|
Hello everyone,
I have an issue with WMB's xsl transformaiton node.
I have a lot of xsl files. These xslts making an easy xml->xml transformation, but the input xml have some CDATA in it.
Here's the relevant part of the xsl:
Code: |
<xsl:template match="ns1:myTag">
<ns1:myTag>
<xsl:value-of select="XMLTREE1" disable-output-escaping="yes"/>
</ns1:myTag>
</xsl:template> |
Here's the data inside the input xml:
Code: |
<XMLTREE1>
<![CDATA[<metaData><value>value1</value></metaData>]]>
</XMLTREE1> |
And i would like to see this in the output:
Code: |
<ns1:myTag xmlns:ns1="http://mynamespace/">
<metaData>
<value>value1</value>
</metaData>
</ns1:myTag> |
The problem is the next: i made the xsl files in eclipse and used the built-in xslt processor to test them. Each xsl file was good, with a properly mapped metaData in the output.
But when i used it in my broker flow, i didn't see anything in the output from the CDATA section.
I was thinking if the xsl:value-of can only get the value of an element and when it tries the CDATA section it doesn't see any (only a big string).
I even tried
Code: |
<xsl:copy-of select="./*" /> |
but this isn't working either (there is no real node inside XMLTREE1, only a string).
(I tried
Code: |
<xsl:copy-of select="./*" /> |
too, but that copies the XMLTREE tag as well, and i don't need it, only the content of it)
Do you have any ideas, what can be the problem? Why is it working in eclipse and not when i'm using it from the flow?
(I can't switch to another type of method, i need to do this from xsl, because it's called by a lot of system, and i don't want to break the homogeneity of the system (lots of layers, lots of flows))
Thanks,
Tamas |
|
Back to top |
|
 |
kimbert |
Posted: Fri Jan 23, 2015 2:18 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
I was thinking if the xsl:value-of can only get the value of an element and when it tries the CDATA section it doesn't see any (only a big string). |
According to the XML specfication, a CDATA section *is* a 'big string'. So that is how XSLT will see it.
Quote: |
Why is it working in eclipse and not when i'm using it from the flow? |
Good question. The the XSLT processor in Eclipse would *must* treat a CDATA section exactly like a string value. If it did not then it would be a serious defect in the XSLT processor. I think you need to check exactly what the Eclipse program is doing.
It's hard to say any more without seeing an actual example. Can you reproduce this with a simple XML file and XSLT? _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
szfamman |
Posted: Fri Jan 23, 2015 2:58 am Post subject: |
|
|
Newbie
Joined: 07 Jul 2014 Posts: 9
|
Hi kimbert,
Thank you for the fast response.
Here are the xsl/xml files you need:
XSL:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns1 ="http://mynamespace/">
<xsl:output method="xml" version="1.0" encoding="UTF-8"
indent="yes" omit-xml-declaration="yes" />
<xsl:template match="/">
<xsl:apply-templates select="ns1:myOperation" />
</xsl:template>
<xsl:template match="ns1:myOperation">
<ns1:myOperation>
<xsl:apply-templates select="version" />
<xsl:value-of select="XMLTREE1" disable-output-escaping="yes"/>
</ns1:myOperation>
</xsl:template>
<xsl:template match="version">
<xsl:element name="version">
<xsl:value-of select="." />
</xsl:element>
</xsl:template>
</xsl:stylesheet> |
XML:
Code: |
<ns1:myOperation xmlns:ns1="http://mynamespace/">
<version>1</version>
<XMLTREE1>
<![CDATA[<metaData><value>value1</value></metaData>]]>
</XMLTREE1>
</ns1:myOperation> |
I tested it with eclipse, and here is the output:
Code: |
<ns1:myOperation xmlns:ns1="http://mynamespace/">
<version>1</version>
<metaData>
<value>value1</value>
</metaData>
</ns1:myOperation> |
One more information: eclipse uses JAX-P SAX Processor for the transformation. |
|
Back to top |
|
 |
kimbert |
Posted: Fri Jan 23, 2015 4:56 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Please see this question on StackOverflow:
http://stackoverflow.com/questions/17495177/cdata-section-is-lost-when-xslt-transformation-is-applied
The Eclipse XSLT engine does not know whether the string in the XMLTREE node was CDATA or PCDATA ( you may need to look up those terms in the XML specification ). So it just outputs the string value of XMLTREE as PCDATA ( unless the stylesheet explicity asks for CDATA to be used ).
The Eclipse XML output should look kike this ( notice that the < and > have been replaced with character entities ):
Code: |
<ns1:myOperation xmlns:ns1="http://mynamespace/">
<version>1</version>
<metaData>
<value>value1</value>
</metaData>
</ns1:myOperation> |
When the Eclipse XSLT processor removes the CDATA tags then it *must* escape the < and > in the output string. I recommend that you check the Eclipse output once more. Maybe your viewer is automatically displaying < as < and > as >. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
szfamman |
Posted: Fri Jan 23, 2015 6:11 am Post subject: |
|
|
Newbie
Joined: 07 Jul 2014 Posts: 9
|
I didn't find any setting about this.
Do have any idea how to solve this (how to tell the xslt engine that there are real elements in that CDATA field)?
Any suggestions can come in handy.
Thanks,
Tamas |
|
Back to top |
|
 |
kimbert |
Posted: Fri Jan 23, 2015 8:58 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
Do have any idea how to solve this (how to tell the xslt engine that there are real elements in that CDATA field)? |
You cannot. The content of a CDATA section is text. Not elements.
If you want to treat the content of a CDATA section as an XML document then you must perform a second parsing operation on the text value of the CDATA section. _________________ Before you criticize someone, walk a mile in their shoes. That way you're a mile away, and you have their shoes too. |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|