|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
XSL Transformation doesn't works |
« View previous topic :: View next topic » |
Author |
Message
|
LuisR |
Posted: Tue Jun 21, 2016 11:54 am Post subject: XSL Transformation doesn't works |
|
|
Apprentice
Joined: 07 Jun 2016 Posts: 25
|
Hello,
I was using an XSL transformation to sort the SOAP response that I need to send back to the invokers but it doesn't works, though I've tested in several different ways.
Why XSL? Because I've got a lot of similar documents (without schema) that I need to sort and this way is really more understandable and modular.
The XSL was developed in XMLSpy and tested on that tool. After that I've put it on Message Broker and fixed so I have no errors and I've tested that new XSL on XMLSpy again and with several documents and it works.
But when I run the transformation in a flow it copies the entire message without any transformation.
Can you please help me? I was trying with different XPaths that works in XMLSpy and I got the same response from the Message Broker flow.
Thanks
XML to transform:
The field "sql" signals the sorting field and the sorting order; in this case the sort is over the CODATR field and in desceding order.
Code: |
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<NS1:Search_Atributos_ClienteResponse xmlns:NS1="http://tempuri.org/">
<NS1:Search_Atributos_ClienteResult>
<NS1:datos>
<NS2:schema id="NewDataSet" xmlns:NS2="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<NS2:element msdata:IsDataSet="true" msdata:MainDataTable="tabla" msdata:UseCurrentLocale="true" name="NewDataSet">
<NS2:complexType>
<NS2:choice maxOccurs="unbounded" minOccurs="0">
<NS2:element name="tabla">
<NS2:complexType>
<NS2:sequence>
<NS2:element minOccurs="0" name="RUTCLI" type="xs:string"/>
<NS2:element minOccurs="0" name="DVCLIE" type="xs:string"/>
<NS2:element minOccurs="0" name="APEPAT" type="xs:string"/>
<NS2:element minOccurs="0" name="APEMAT" type="xs:string"/>
<NS2:element minOccurs="0" name="NOMPRI" type="xs:string"/>
<NS2:element minOccurs="0" name="NOMSEG" type="xs:string"/>
<NS2:element minOccurs="0" name="CODATR" type="xs:string"/>
<NS2:element minOccurs="0" name="VALATR" type="xs:string"/>
<NS2:element minOccurs="0" name="FECINI" type="xs:string"/>
<NS2:element minOccurs="0" name="FECTER" type="xs:string"/>
<NS2:element minOccurs="0" name="FECCRE" type="xs:string"/>
<NS2:element minOccurs="0" name="NOMUSU" type="xs:string"/>
</NS2:sequence>
</NS2:complexType>
</NS2:element>
</NS2:choice>
</NS2:complexType>
</NS2:element>
</NS2:schema>
<diffgr:diffgram xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<NS1:DocumentElement>
<NS1:tabla diffgr:hasChanges="inserted" diffgr:id="tabla1" msdata:rowOrder="0">
<NS1:RUTCLI>23877564-</NS1:RUTCLI>
<NS1:DVCLIE>-</NS1:DVCLIE>
<NS1:APEPAT>DE TAL</NS1:APEPAT>
<NS1:APEMAT/>
<NS1:NOMPRI>FULANO</NS1:NOMPRI>
<NS1:NOMSEG/>
<NS1:CODATR>CODE1</NS1:CODATR>
<NS1:VALATR>VALUE1</NS1:VALATR>
<NS1:FECINI>2016-05-21T00:00:00-04:00</NS1:FECINI>
<NS1:FECCRE>0001-01-01T00:00:00</NS1:FECCRE>
<NS1:FECTER>2016-07-21T00:00:00-04:00</NS1:FECTER>
<NS1:NOMUSU>NA</NS1:NOMUSU>
</NS1:tabla>
<NS1:tabla diffgr:hasChanges="inserted" diffgr:id="tabla2" msdata:rowOrder="1">
<NS1:RUTCLI>23877564-</NS1:RUTCLI>
<NS1:DVCLIE>-</NS1:DVCLIE>
<NS1:APEPAT>DE TAL</NS1:APEPAT>
<NS1:APEMAT/>
<NS1:NOMPRI>FULANO</NS1:NOMPRI>
<NS1:NOMSEG/>
<NS1:CODATR>CODE2</NS1:CODATR>
<NS1:VALATR>VALUE2</NS1:VALATR>
<NS1:FECINI>2016-05-22T00:00:00-04:00</NS1:FECINI>
<NS1:FECCRE>0001-01-01T00:00:00</NS1:FECCRE>
<NS1:FECTER>2016-07-22T00:00:00-04:00</NS1:FECTER>
<NS1:NOMUSU>NA</NS1:NOMUSU>
</NS1:tabla>
<NS1:tabla diffgr:hasChanges="inserted" diffgr:id="tabla3" msdata:rowOrder="2">
<NS1:RUTCLI>23877564-</NS1:RUTCLI>
<NS1:DVCLIE>-</NS1:DVCLIE>
<NS1:APEPAT>DE TAL</NS1:APEPAT>
<NS1:APEMAT/>
<NS1:NOMPRI>FULANO</NS1:NOMPRI>
<NS1:NOMSEG/>
<NS1:CODATR>CODE3</NS1:CODATR>
<NS1:VALATR>VALUE3</NS1:VALATR>
<NS1:FECINI>2016-05-23T00:00:00-04:00</NS1:FECINI>
<NS1:FECCRE>0001-01-01T00:00:00</NS1:FECCRE>
<NS1:FECTER>2016-07-23T00:00:00-04:00</NS1:FECTER>
<NS1:NOMUSU>NA</NS1:NOMUSU>
</NS1:tabla>
</NS1:DocumentElement>
</diffgr:diffgram>
</NS1:datos>
<NS1:sql>CODATR|DESC</NS1:sql>
<NS1:codigo_error>0</NS1:codigo_error>
</NS1:Search_Atributos_ClienteResult>
</NS1:Search_Atributos_ClienteResponse>
</soapenv:Body>
</soapenv:Envelope>
|
XSL transformation:
Code: |
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" xmlns:NS2="http://www.w3.org/2001/XMLSchema" xmlns:NS1="http://tempuri.org/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:variable name="sortColumn" select="substring-before(/*/*/*/*/NS1:sql, '|')" />
<xsl:variable name="sortOrder" select="substring-after(/*/*/*/*/NS1:sql, '|')" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/*/*/*/NS1:datos/diffgr:diffgram/NS1:DocumentElement">
<xsl:if test="$sortOrder = 'ASC'">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="NS1:tabla">
<xsl:sort select="*[local-name() = $sortColumn]" order="ascending" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:if>
<xsl:if test="$sortOrder = 'DESC'">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="NS1:tabla">
<xsl:sort select="*[local-name() = $sortColumn]" order="descending" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:if>
</xsl:template>
<xsl:template match="/*/*/*/*/NS1:sql">
<xsl:copy>NA</xsl:copy>
</xsl:template>
</xsl:stylesheet>
|
|
|
Back to top |
|
 |
LuisR |
Posted: Wed Jun 22, 2016 7:23 am Post subject: |
|
|
Apprentice
Joined: 07 Jun 2016 Posts: 25
|
|
Back to top |
|
 |
mqjeff |
Posted: Wed Jun 22, 2016 7:29 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
I'm terrible at XSLT.
Some points.
Broker does use a very old version of XSLT in the XSLTransformation node - it's v1.x - you seem to have cued in on that with your download of the version of Xalan.
Broker XSLT is not working against the XML document, it's operating against the logical message tree.
Broker XMLNSC Logical Message Trees have full text namespaces attached to every element - not namespace reference like NS1 or etc. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
LuisR |
Posted: Wed Jun 22, 2016 8:01 am Post subject: |
|
|
Apprentice
Joined: 07 Jun 2016 Posts: 25
|
Thanks for your answer, mqjeff!
The logical message tree doesn't have the Envelope nor Body in it so with just deleting a "/*/*" worked perfectly.
I'll leave the XSL for anyone who needs to sort a DataSet inside a SOAP response.
Thanks again |
|
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
|
|
|
|