English 中文(简体)
xml 转换 使用 xlts, 按字母顺序
原标题:xml transform using xlts, order by alphabet
  • 时间:2012-05-25 11:33:12
  •  标签:
  • java
  • xml
  • xslt

我有这个 XSD XML( 申请成为 WSDL) 文件 :

<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>  

我要用 javax. transformation 将此文件转换为另一个文件, 其中 messages 将按字母顺序( 使用字符串的名称 ) 。

<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>  

我需要什么 XSLT 文件?

最佳回答

这个XSLT变形会做你想做的事

<?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>

<强 > 输出

<?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>
问题回答

暂无回答




相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签