Here, I do not know the exact type of Element Names under <Structure> tag. Currently there are Elements of Type AAA, BBB, CCC and DDD. But they can be random and may have different Element names (e.g. YYY).
I wish to sort the all Elements Alphabetically based on their Element name(AAA,BBB,CCC.....) and among multiple Elements (e.g. Among two elements named "AAA"), each element to sorted based on thier Name (e.g Axle_A, Wheel....).
Also the Child Elements under each child element(discipline,nature,maturity) get sorted alphabetically.
Sorry for this type of Printing. Actually some problem with the Text Editor of this forum.
Hope this you can be visualized properly. Trying one more time.Hello Morten,</span></span> </span>The XSL is working absolutely fine :). Thank you for that.</span></span> </span>But I am facing new problem as the actual Root of XML is <Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.myweb.com/xsd/myxsd"></span></span> </span>I get introduced in each element as below:</span></span> </span>"<AAA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="1" xsi:type="AAAType" name="Axle_A">"</span></span> </span>Here is what I used in XSL:</span></span> </span><xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.myweb.com/xsd/myxsd"> </span></span> </span> </span>Rest of XSL is same..</span></span> </span>Regards,</span></span>Sachin</span></span>
Yes, logic is working absolutely fine. I just needed to add same logic (nested loop) to work(arrange alphabetically) it for one more level in XML; to be specific for this level <discipline>Design</discipline> <maturity>Maturity</maturity>
And If I have one more level, then I need to add the same logic inside loop. But I thinks it’s not good idea to just keep on adding the same loop inside another loop if we have the more levels in the XML.
Can we call the previous loop again if there are further levels down till we encounter last level in the XML (recursive loop), to make it more generic ?
Also one more thing I do not get indentations write for inside XML elements though I have set <xsl:output indent="yes" encoding="UTF-16" /> in the XSLT. I get something like this:
But I want output as : <Structure> <AAA id="1" type="AAAType" name="Axle_A"> <discipline>Design</discipline> <maturity>Maturity</maturity> <nature>1</nature> </AAA>
Well, it sound like you are trying to do an awful lot here. I guess you could add infinite levels of sorting by doing a recursive template. Take a look at the sitemap XSLT for a sample of that.
What is the reason for sorting these data? Do you just have to sort the data, and then display them on the page, or what are you trying to achieve? And why does it need to be indented?
Sorry for late reply. Actually I am sorting the data and using it for comparison with reference one.
Everytime, My application generates a XML which is used to compare with a Reference XML. But as the requence may change, so I first sort the data and then use for validation.
Yes I wish to use Recursive template as I do not know how many levels are there in XML.
Tricky Sorting Problem in XSLT!
Hello,
I have started using XSLT recently and do not have much hands on it. I have done some XSL for the specific requirements.
But here is a bit tricky for me.
I have a XML file having structure like below:
----------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<Model>
<Structure>
<AAA id="1" xsi:type="AAAType" name="Axle_A">
<discipline>Design</discipline>
<nature>1</nature>
<maturity>Maturity</maturity>
</AAA>
<BBB id="2" xsi:type="BBBType" name="Board.1">
<IsAggregatedBy>1</IsAggregatedBy>
<IsInstanceOf>3</IsInstanceOf>
<RelativeMatrix>1 0 0 0 1 0 0 0 1 0 0 0</RelativeMatrix>
</BBB>
<CCC version="1.0" id="5" associatedFile="BoardDoc_2_c93ea71b_f40_4a49f717_12a5.3DRep" xsi:type="CCCType" format="UVR" name="BoardDoc">
<description>Rep of the Board</description>
<discipline>Design</discipline>
<maturity>Maturity</maturity>
</CCC>
<BBB id="6" xsi:type="BBBType" name="Axle.Front">
<IsAggregatedBy>1</IsAggregatedBy>
<IsInstanceOf>7</IsInstanceOf>
<RelativeMatrix>1 0 0 0 1 0 0 0 1 100 0 -20</RelativeMatrix>
</BBB>
<DDD id="4" xsi:type="DDDType" name="InstRep1">
<description>RepInstOf_BoardDoc</description>
<IsAggregatedBy>3</IsAggregatedBy>
<IsInstanceOf>5</IsInstanceOf>
</DDD>
<CCC version="1.0" id="9" associatedFile="abc.3DRep" xsi:type="CCCType" format="MyFomat" name="AxleDoc">
<description>Rep of the Axle</description>
<discipline>Design</discipline>
</CCC>
<AAA id="11" xsi:type="AAAType" name="Wheel">
<description>Wheel_Ref</description>
<nature>1</nature>
</AAA>
<DDD id="12" xsi:type="DDDType" name="InstRep3">
<description>RepInstOf_WheelDoc</description>
<IsAggregatedBy>11</IsAggregatedBy>
<IsInstanceOf>13</IsInstanceOf>
</DDD>
</Structure>
</Model>
------------------------------------------------------------------------------------------------------------------
Here, I do not know the exact type of Element Names under <Structure> tag. Currently there are Elements of Type AAA, BBB, CCC and DDD. But they can be random and may have different Element names (e.g. YYY).
I wish to sort the all Elements Alphabetically based on their Element name(AAA,BBB,CCC.....) and among multiple Elements (e.g. Among two elements named "AAA"), each element to sorted based on thier Name (e.g Axle_A, Wheel....).
Also the Child Elements under each child element(discipline,nature,maturity) get sorted alphabetically.
The Expected result after sorting is:
------------------------------------------------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<Model>
<Structure>
<AAA id="1" xsi:type="AAAType" name="Axle_A">
<discipline>Design</discipline>
<nature>1</nature>
<maturity>Maturity</maturity>
</AAA>
<AAA id="11" xsi:type="AAAType" name="Wheel">
<description>Wheel_Ref</description>
<nature>1</nature>
</AAA>
</BBB>
<BBB id="6" xsi:type="BBBType" name="Axle.Front">
<IsAggregatedBy>1</IsAggregatedBy>
<IsInstanceOf>7</IsInstanceOf>
<RelativeMatrix>1 0 0 0 1 0 0 0 1 100 0 -20</RelativeMatrix>
</BBB>
<BBB id="2" xsi:type="BBBType" name="Board.1">
<IsAggregatedBy>1</IsAggregatedBy>
<IsInstanceOf>3</IsInstanceOf>
<RelativeMatrix>1 0 0 0 1 0 0 0 1 0 0 0</RelativeMatrix>
<CCC version="1.0" id="9" associatedFile="abc.3DRep" xsi:type="CCCType" format="MyFomat" name="AxleDoc">
<description>Rep of the Axle</description>
<discipline>Design</discipline>
</CCC>
<CCC version="1.0" id="5" associatedFile="BoardDoc_2_c93ea71b_f40_4a49f717_12a5.3DRep" xsi:type="CCCType" format="UVR" name="BoardDoc">
<description>Rep of the Board</description>
<discipline>Design</discipline>
<maturity>Maturity</maturity>
</CCC>
<DDD id="4" xsi:type="DDDType" name="InstRep1">
<description>RepInstOf_BoardDoc</description>
<IsAggregatedBy>3</IsAggregatedBy>
<IsInstanceOf>5</IsInstanceOf>
</DDD>
<DDD id="12" xsi:type="DDDType" name="InstRep3">
<description>RepInstOf_WheelDoc</description>
<IsAggregatedBy>11</IsAggregatedBy>
<IsInstanceOf>13</IsInstanceOf>
</DDD>
</Structure>
</Model>
------------------------------------------------------------------------------
Thanks in advacne.
Regards,
Sachin
Something like:
<xsl:for-each select="//Structure/child::node()">
<xsl:sort select="name()"/>
<xsl:value-of select="name()"/>
<xsl:for-each select="child::node()">
<xsl:sort select="name()"/>
<xsl:value-of select="name()"/>
<xsl:value-of select="text()"/>
</xsl:for-each>
</xsl:for-each>
Just tested this out, and it should do what you want:
Update... just saw the extra requirements....
Hello Darren,
Here is the XSL I used:
xsl:stylesheet</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> version</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">1.1</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> xmlns:xsl</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">http://www.w3.org/1999/XSL/Transform</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span>xsl:output</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> indent</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">yes</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> encoding</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">UTF-16</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:template</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> match</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">Structure</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:element</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> name</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">Structure</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><span style="mso-tab-count: 1"> </span></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:for-each</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">child::node()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:sort</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">name()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span><span style="mso-spacerun: yes"> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:value-of</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">name()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><span style="mso-spacerun: yes"> </span><span style="mso-tab-count: 3"> </span><span style="mso-spacerun: yes"> </span></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:for-each</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">child::node()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:sort</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">name()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span><span style="mso-spacerun: yes"> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:value-of</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">name()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:value-of</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">text()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:for-each</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:for-each</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:element</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:template</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span> </span></span>xsl:template</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> match</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">@* | node()</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:copy</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:copy-of</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: red; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> select</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">="</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">@*</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">"/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> <span style="mso-tab-count: 2"> </span></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"><</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:apply-templates</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">/></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> <span style="mso-tab-count: 2"> </span></span> </span></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: maroon; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">xsl:copy</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span>xsl:template</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"> </span> </span>xsl:stylesheet</span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: blue; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white">></span><span style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: 'Arial','sans-serif'; mso-highlight: white"></span>
And here is the Output:<?xml version="1.0" encoding="UTF-16"?></span><span style="font-size: 10pt; background: white; color: black; font-family: "Arial","sans-serif"; mso-highlight: white;"></span> </span></span><span style="font-size: 10pt; background: white; color: blue; font-family: "Arial","sans-serif"; mso-highlight: white;"><</span><span style="font-size: 10pt; background: white; color: maroon; font-family: "Arial","sans-serif"; mso-highlight: white;">Structure</span><span style="font-size: 10pt; background: white; color: blue; font-family: "Arial","sans-serif"; mso-highlight: white;">></span><span style="font-size: 10pt; background: white; color: black; font-family: "Arial","sans-serif"; mso-highlight: white;">AAAdisciplineDesignmaturityMaturitynature1AAAdescriptionWheel_Refnature1BBBIsAggregatedBy1IsInstanceOf3RelativeMatrix1 0 0 0 1 0 0 0 1 0 0 0BBBIsAggregatedBy1IsInstanceOf7RelativeMatrix1 0 0 0 1 0 0 0 1 100 0 -20CCCdescriptionRep of the BoarddisciplineDesignmaturityMaturityCCCdescriptionRep of the AxledisciplineDesignDDDdescriptionRepInstOf_BoardDocIsAggregatedBy3IsInstanceOf5DDDdescriptionRepInstOf_WheelDocIsAggregatedBy11IsInstanceOf13</span><span style="font-size: 10pt; background: white; color: blue; font-family: "Arial","sans-serif"; mso-highlight: white;"></</span><span style="font-size: 10pt; background: white; color: maroon; font-family: "Arial","sans-serif"; mso-highlight: white;">Structure</span><span style="font-size: 10pt; background: white; color: blue; font-family: "Arial","sans-serif"; mso-highlight: white;">></span><span style="font-size: 10pt; background: white; color: black; font-family: "Arial","sans-serif"; mso-highlight: white;"></span>
It is sorting the Elements Alhabetically but I do not know how to write/create the Actual elements.
Regards,
Sachin
Looks like something has been copied and pasted from word there!
Hello Morten,
The XSL is working absolutely fine :). Thank you for that.
<
Sorry for this type of Printing. Actually some problem with the Text Editor of this forum.
Hope this you can be visualized properly. Trying one more time.Hello Morten,</span></span> </span>The XSL is working absolutely fine :). Thank you for that.</span></span> </span>But I am facing new problem as the actual Root of XML is <Model xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.myweb.com/xsd/myxsd"></span></span> </span>I get introduced in each element as below:</span></span> </span>"<AAA xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" id="1" xsi:type="AAAType" name="Axle_A">"</span></span> </span>Here is what I used in XSL:</span></span> </span><xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.myweb.com/xsd/myxsd"> </span></span> </span> </span>Rest of XSL is same..</span></span> </span>Regards,</span></span>Sachin</span></span>
try copying to your favorite texteditor (notepad) and then to the forum ..
Try this:
Hoping this code is formatting correctly.
Hello Morten,
Yes, logic is working absolutely fine. I just needed to add same logic (nested loop) to work(arrange alphabetically) it for one more level in XML; to be specific for this level
<discipline>Design</discipline>
<maturity>Maturity</maturity>
And If I have one more level, then I need to add the same logic inside loop. But I thinks it’s not good idea to just keep on adding the same loop inside another loop if we have the more levels in the XML.
Can we call the previous loop again if there are further levels down till we encounter last level in the XML (recursive loop), to make it more generic ?
Also one more thing I do not get indentations write for inside XML elements though I have set <xsl:output indent="yes" encoding="UTF-16" /> in the XSLT.
I get something like this:
<Structure>
<AAA id="1" type="AAAType" name="Axle_A"><discipline>Design</discipline><maturity>Maturity</maturity><nature>1</nature></AAA>
But I want output as :
<Structure>
<AAA id="1" type="AAAType" name="Axle_A">
<discipline>Design</discipline>
<maturity>Maturity</maturity>
<nature>1</nature>
</AAA>
Regards,
Sachin
Well, it sound like you are trying to do an awful lot here. I guess you could add infinite levels of sorting by doing a recursive template. Take a look at the sitemap XSLT for a sample of that.
What is the reason for sorting these data? Do you just have to sort the data, and then display them on the page, or what are you trying to achieve? And why does it need to be indented?
Hello Morten,
Sorry for late reply. Actually I am sorting the data and using it for comparison with reference one.
Everytime, My application generates a XML which is used to compare with a Reference XML. But as the requence may change, so I first sort the data and then use for validation.
Yes I wish to use Recursive template as I do not know how many levels are there in XML.
is working on a reply...