|
Subject: Re: [xsl] How Do I Exclude Portions Of XML When XForming XML To XML From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx> Date: Tue, 24 Feb 2004 23:31:10 -0500 |
> I have a sample XML file and I want to transform this to a different XML file while omitting part of the original xml.
> Any help would be appreciated.
T:\ftemp>type gary.xml
<Auto>
<CustId>
<SPName>com.anysystem</SPName>
<CustPermId/>
<CustLoginId>fred</CustLoginId>
</CustId>
<BasicVehInfo>
<ModelYear>1994</ModelYear>
<VehIdentificationNumber>1ABCD123456</VehIdentificationNumber>
</BasicVehInfo>
</Auto>
T:\ftemp>type mappings.xml
<?xml version="1.0" encoding="iso-8859-1"?>
<mappings>
<mapping old="Auto" new="Vehicle"/>
<mapping old="BasicVehInfo" new="VehicleData"/>
<mapping old="ModelYear" new="VehicleYear"/>
<mapping old="VehIdentificationNumber" new="VIN"/>
</mappings>T:\ftemp>type gary.xsl <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="*">
<xsl:variable name="oldname" select="name(.)"/>
<xsl:variable name="newname">
<xsl:for-each select="document('mappings.xml')">
<xsl:value-of select="key('names',$oldname)"/>
</xsl:for-each>
</xsl:variable>
<xsl:if test="string($newname)">
<xsl:element name="{$newname}">
<xsl:apply-templates select="@*|node()"/>
</xsl:element>
</xsl:if>
</xsl:template><xsl:template match="@*|text()"><!--identity for all other nodes-->
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<!--this cleans up the output-->
<xsl:template match="text()[not(normalize-space())]"/>T:\ftemp>saxon gary.xml gary.xsl
<?xml version="1.0" encoding="utf-8"?>
<Vehicle>
<VehicleData>
<VehicleYear>1994</VehicleYear>
<VIN>1ABCD123456</VIN>
</VehicleData>
</Vehicle>
T:\ftemp>
-- Public courses: Spring 2004 world tour of hands-on XSL instruction Each week: Monday-Wednesday: XSLT/XPath; Thursday-Friday: XSL-FO United States: Washington, DC March 15; San Francisco, CA March 22 Finland April 26; Hong Kong May 17; Germany May 24; London June 07 World-wide on-site corporate, government & user group XML training
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 (F:-0995) Male Breast Cancer Awareness http://www.CraneSoftwrights.com/s/bc
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: [xsl] Tag insertion problem whi, Dipesh Khakhkhar | Thread | RE: [xsl] How Do I Exclude Portions, Gary Fix |
| RE: [xsl] Translating XSD into an X, Michael Kay | Date | [xsl] Multi level grouping question, Kent Seegmiller |
| Month |