Reputation: 29693
I have this XSD XML (happens to be a WSDL) file:
<definitions targetNamespace="http://soft.com/" name="LoggingWebService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.config.softid.softcomputer.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://soft.com/" schemaLocation="my.xsd"/>
</xsd:schema>
</types>
<message name="log">
<part name="parameters" element="tns:log"/>
</message>
<message name="getLogs">
<part name="parameters" element="tns:getLogs"/>
</message>
<message name="getLogsResponse">
<part name="parameters" element="tns:getLogsResponse"/>
</message>
</definitions>
I want transform this file using javax.transformation
to another file, where messages
will be ordered by alphabet (using string in 'name').
<definitions targetNamespace="http://soft.com/" name="LoggingWebService" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.config.softid.softcomputer.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://soft.com/" schemaLocation="my.xsd"/>
</xsd:schema>
</types>
<message name="getLogs">
<part name="parameters" element="tns:getLogs"/>
</message>
<message name="getLogsResponse">
<part name="parameters" element="tns:getLogsResponse"/>
</message>
<message name="log">
<part name="parameters" element="tns:log"/>
</message>
</definitions>
What XSLT file I need for this? Help me plz
Upvotes: 0
Views: 2241
Reputation: 126722
This XSLT transform will do what you want.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
version="1.0" >
<xsl:output method="xml" indent="yes" />
<xsl:strip-space elements="*"/>
<xsl:template match="/wsdl:definitions" >
<xsl:copy>
<xsl:copy-of select="wsdl:types" />
<xsl:for-each select="wsdl:message" >
<xsl:sort select="@name" />
<xsl:copy-of select="current()"/>
</xsl:for-each>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
output
<?xml version="1.0" encoding="utf-8"?>
<definitions xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://ws.config.softid.softcomputer.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<types>
<xsd:schema>
<xsd:import namespace="http://soft.com/" schemaLocation="my.xsd"/>
</xsd:schema>
</types>
<message name="getLogs">
<part name="parameters" element="tns:getLogs"/>
</message>
<message name="getLogsResponse">
<part name="parameters" element="tns:getLogsResponse"/>
</message>
<message name="log">
<part name="parameters" element="tns:log"/>
</message>
</definitions>
Upvotes: 1