Subject: Re: [xsl] XML to XML transformation From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Fri, 02 Aug 2002 13:13:48 -0400 |
I need to transform one XML to another XML. Some of the elements in the source XML has an attribute xsi:type and the value is a java class name. In the output xml I want to remove this attribute and change the name of the element to something based on the java class name.
T:\ftemp>type subramanian.xml <javaobject xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="java:a.b.c" attr1="123"> <a-subelement>Test</a-subelement> <!--end of test--> </javaobject>
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" exclude-result-prefixes="xsi" version="1.0">
<xsl:template match="*[@xsi:type]"><!--elements of an XS type--> <xsl:element name="{translate( substring-after( @xsi:type, 'java:' ), '.', '' )}"> <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 theinput 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"?> <abc attr1="123"> <a-subelement>Test</a-subelement> <!--end of test--> </abc> T:\ftemp>
-- 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 -> |
---|---|---|
[xsl] XML to XML transformation, Subramanian Subraman | Thread | [xsl] nodeset extension in .Net?, bryan |
RE: [xsl] merge tree structure with, McNally, David | Date | [xsl] Internationalization, Brian Grainger |
Month |