|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: How to map XML to XML according to element values
Roy,
There are a number of ways, more-or-less brutish, to accomplish what you want to do. The easiest technique to implement and to maintain would use keys. It is not the easiest technique to understand because you have to see how keys work. Given that, however, it beats any of the other methods. You would start by declaring a key that would allow you to retrieve your employees by their department code: <xsl:key name="employees-by-dept" match="Employee" use="Dept"/> this matches Employee elements, using the value of its Dept element child as the key for each. Then, in your template for Department, in addition to doing what you want with its children, you merely going and fetching the matching employees: <xsl:template match="Department"> <xsl:copy> <!-- this copies the Department node itself since we want it in our output --> <xsl:copy-of select="*"/> <!-- inside the Department, we use the copy-of to copy over the existing DeptCode and Name children --> <xsl:apply-templates select="key('employees-by-dept', DeptCode)"/> <!-- this instruction says to go get the nodes returned by the key, using the value in the DeptCode child as the key value, and apply templates to them. Naturally, since every Department has a different DeptCode child, we'll get a different set of Employees for each different Department node. --> </xsl:copy> </xsl:template> then you just need a template to process your Employee elements: <xsl:template match="Employee">
<xsl:copy>
<xsl:copy-of select="EmpNo | Name"/>
<!-- this time we copy the EmpNo and Name children, but leave out
the Dept for the obvious reasons. -->
</xsl:copy>
</xsl:template>That should do it. Try running it. If you understand XSLT's template-driven ("rule-based") processing, and see how the key works, it should all make sense. Cheers, Wendell At 01:25 PM 11/26/01, you wrote: I have the following XML, ====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ====================================================================== 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
|

Cart








