[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Getting the deepest node and calculating relative path
Greetings, I need to transform an XML that looks like: <Root> <Paths> <Path value="/Catalog/Department/Product/SKU"/> <Path value="/Catalog/Department/@dept_id"/> <Path value="/Catalog/Department/Product/Name"/> <Path value="/Catalog/Department/Product/Price"/> <Path value="/Catalog/Department/Product/Variant/Name"/> </Paths> </Root> to something that looks like: <Root> <LongestPath>/Catalog/Department/Product/Variant/Name</LongestPath> <RelPaths> <RelPath value="../../SKU"/> <RelPath value="../../../@dept_id"/> <RelPath value="../../Name"/> <RelPath value="../../Price"/> <RelPath value="."/> </RelPaths> </Root> The basic idea is to get the <Path> element whose value attribute holds the XPath expression that, if evaluated, would result in nodes at the deepest level, relative to other paths specified in the value attributes of sibling <Path> elements. The XPath expressions themselves are meant to be used on another XML; only their string values are important here. A simple logic that would work for me would be to cut each XPath string to the rightmost "/" character, and simply return the longest string out of all such cut strings (If you notice carefully, these XPath expressions are defined such that in a given context, the parent nodes of the resulting node-set of each XPath expression belong to the same branch of an arbitrary tree). After getting the longest path, I need to output a <RelPath> node corresponding to each <Path> node such that the value attribute contains the relative path of the corresponding Path element, relative to the longest path. This should be pretty clear from the output xml I've provided above. Is this kind of complex(?) transformation possible in xslt. Theoretically I have all the information I need in the source XML that should be required to perform the required transformation, but I'm just not able to figure out how. It'll be a pity if I have to "manually" perform this transformation using Java. Please let me know if any solutions exist. Thanks, Iresh XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|