Sort xml and write to xml

G

gdevah

Hi , I have an xml file with below data,and would like to sort this
based on the classname. I did try some xsl but not much use.

<?xml version="1.0" encoding="UTF-8"?>
<document>
<ObjectDataForm classname="AC" displayname="ACL">
<ObjectMenu name="ACb" menuFileName="AC.xml"/>
<property name="dName" display="NE" swingType="JLabel"/>
<property name="name" display="Name" swingType="JLabel"/>
<property name="aclCfgTblACLID" swingType="JLabel"/>
</ObjectDataForm>
<ObjectDataForm classname="A13" displayname="A13">
<ObjectMenu name="A13" menuFileName="A13.xml"/>
<property name="AName" display="NE" swingType="JLabel"/>
<property name="name" display="Name"swingType="JLabel"/>
</ObjectDataForm>
</document>

Thanks a lot for reading and ...
Devah
 
M

Martin Honnen

Hi , I have an xml file with below data,and would like to sort this
based on the classname. I did try some xsl but not much use.

<?xml version="1.0" encoding="UTF-8"?>
<document>
<ObjectDataForm classname="AC" displayname="ACL">
<ObjectMenu name="ACb" menuFileName="AC.xml"/>
<property name="dName" display="NE" swingType="JLabel"/>
<property name="name" display="Name" swingType="JLabel"/>
<property name="aclCfgTblACLID" swingType="JLabel"/>
</ObjectDataForm>
<ObjectDataForm classname="A13" displayname="A13">
<ObjectMenu name="A13" menuFileName="A13.xml"/>
<property name="AName" display="NE" swingType="JLabel"/>
<property name="name" display="Name"swingType="JLabel"/>
</ObjectDataForm>
</document>

You can use XSLT alike the following

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:eek:utput method="xml" encoding="UTF-8" indent="yes" />

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

<xsl:template match="document">
<xsl:copy>
<xsl:apply-templates select="@*" />
<xsl:apply-templates select="ObjectDataForm">
<xsl:sort select="@classname" data-type="text" order="ascending" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Sort xml and output xml 10
Sort XML 6
XML to XML using XSLT 1
problem with schema and xml 2
HTML to XML transform 4
HTML to XML transform 0
XInclude and XLink: how to get working? 2
xalan versus ie xml rendering 3

Members online

Forum statistics

Threads
474,001
Messages
2,570,249
Members
46,846
Latest member
BettinaOsw

Latest Threads

Top