Hello,
I have this XML structure:
I want to sort on DACS.AccessAlias/@xmi.label and DACS.CodeValue/@xmi.label. However, the datatype of the second sort should be based on the value of RAS.ClassificationSchema.Node/@xmi.label (which can be string or number).Code:<XMI> <DACS.AccessAlias xmi.label="Z"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="string"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> </XMI>
This is what I have so far:
Input
Sort.xslCode:<?xml version="1.0" encoding="ISO-8859-1"?> <XMI> <DACS.AccessAlias xmi.label="Z"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="string"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> <DACS.AccessAlias xmi.label="A"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="number"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> </XMI>
OutputCode:<?xml version="1.0" encoding="ISO-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/> <xsl:template match="*[DACS.CodeValue]"> <xsl:copy> <xsl:apply-templates> <xsl:sort select="@xmi.label" data-type="number" order="ascending"/> <xsl:sort select="@xmi.label" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="*[DACS.AccessAlias]"> <xsl:copy> <xsl:apply-templates> <xsl:sort select="@xmi.label" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:copy> </xsl:template> <xsl:template match="@*|node()|text()"> <xsl:copy> <xsl:apply-templates select="@*"/> <xsl:apply-templates /> </xsl:copy> </xsl:template> </xsl:stylesheet>
The desired output I would like is:Code:<?xml version="1.0" encoding="ISO-8859-1"?> <XMI> <DACS.AccessAlias xmi.label="A"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="number"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> <DACS.AccessAlias xmi.label="Z"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="string"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> </XMI>
Thanks for any help.Code:<?xml version="1.0" encoding="ISO-8859-1"?> <XMI> <DACS.AccessAlias xmi.label="A"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="number"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> <DACS.AccessAlias xmi.label="Z"> <DACS.CodingScheme> <DACS.CodingScheme.RV> <RAS.ClassificationSchema.Node xmi.label="string"/> </DACS.CodingScheme.RV> <DACS.CodeValue xmi.label="1"> <DACS.CodeValue.engishDescription>1</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="100"> <DACS.CodeValue.engishDescription>100</DACS.CodeValue.engishDescription> </DACS.CodeValue> <DACS.CodeValue xmi.label="26"> <DACS.CodeValue.engishDescription>26</DACS.CodeValue.engishDescription> </DACS.CodeValue> </DACS.CodingScheme> </DACS.AccessAlias> </XMI>


Reply With Quote
Bookmarks