Subject: RE: [xsl] XML to XML transformation From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 02 Aug 2002 15:00:09 -0400 |
How can I maintain a map of java class name to output element name in the XSL and use the map to generate the output element name whenever I find a xsi:type attribute in the input xml.
Example Class output element name com.integral.Car.BMW bmwCar com.integral.Car.Buick buickCar
T:\ftemp>type subramanian.xml <cars> <javaobject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:com.integral.Car.BMW" attr1="123"> <another-test/> </javaobject> <javaobject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:com.integral.Car.Buick"> <another-test/> </javaobject> <!--end of test--> </cars>
T:\ftemp>type subramanian.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:classtypes="dummy" exclude-result-prefixes="xsi classtypes" version="1.0">
<classtypes:mappings> <!--table of mappings from class string to type name--> <map class="java:com.integral.Car.BMW" type="bmwCar"/> <map class="java:com.integral.Car.Buick" type="buickCar"/> </classtypes:mappings>
<xsl:template match="*[@xsi:type]"><!--elements of an XS type--> <xsl:element name="{$maps[@class=current()/@xsi:type]/@type}"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template>
<xsl:template match="*"> <!--synthesize element with the input name--> <xsl:element name="{name(.)}" namespace="{namespace-uri(.)}"> <xsl:apply-templates select="@*|node()"/> </xsl:element> </xsl:template>
<xsl:template match="@*"> <!--synthesize attribute with the input name--> <xsl:attribute name="{name(.)}" namespace="{namespace-uri(.)}"> <xsl:value-of select="."/> </xsl:attribute> </xsl:template>
<xsl:template match="comment()|processing-instruction()"> <xsl:copy/> </xsl:template>
T:\ftemp>xt subramanian.xml subramanian.xsl <?xml version="1.0" encoding="utf-8"?> <cars> <bmwCar attr1="123"> <another-test/> </bmwCar> <buickCar> <another-test/> </buickCar> <!--end of test--> </cars> T:\ftemp>rem Done!
-- Upcoming hands-on in-depth 3-days XSLT/XPath and/or 2-days XSL-FO: - North America: Sep 30-Oct 4,2002 - Japan: Oct 7-Oct 11,2002
G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ Box 266, Kars, Ontario CANADA K0A-2E0 +1(613)489-0999 (Fax:-0995) ISBN 0-13-065196-6 Definitive XSLT and XPath ISBN 1-894049-08-X Practical Transformation Using XSLT and XPath ISBN 1-894049-07-1 Practical Formatting Using XSLFO XSL/XML/DSSSL/SGML/OmniMark services, books (electronic, printed), articles, training (instructor-live,Internet-live,web/CD,licensed) Next public training: 2002-08-05,26,27,09-30,10-03,07,10
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] XML to XML transformation, Subramanian Subraman | Thread | RE: [xsl] XML to XML transformation, Subramanian Subraman |
RE: [xsl] Internationalization, Hunsberger, Peter | Date | RE: [xsl] Internationalization, Brian Grainger |
Month |