Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 3rd, 2009, 09:32 AM
Registered User
 
Join Date: Mar 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml schema transformation using xslt

hi all,
I need to transform an xml file into a different format (Dublin Core schema) using xslt, file contains different records each record needs to transformed based on a unique ID (in this case its element <guid>) that represents the record. Input file is:

<?xml version="1.0" encoding="UTF-8" ?>
<ListRecords>
<record>
<header>
<identifier>Project_DEM_100</identifier>
<datestamp>2000-02-14T09:23:25Z</datestamp>
</header>
<metadata>
<group xsi:noNamespaceSchemaLocation="http://url.for.schema/schema.xsd">
<title>USER.765</title>
<feed>
<title>My feed</title>
<url>no.url.available</url>
<item>
<!-- Here guid is the unique id for each of the records and also for transformation into another xml format -->
<guid>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</guid>
<events>
<event>
<dateTime>2000-03-26T13:27:49.00</dateTime>
<action>
<actionType>doSomeAtcion</actionType>
<relatedData>
<metadata>
<lom xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM">
<general >
<identifier>
<entry>340</entry>
</identifier>
<identifier>
<identifier>
<catalog>oai</catalog>
<entry>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</entry>
</identifier
<title>
<langstring>
<value>Graduation mw. S. de Caralt</value>
<language>en</language>
</langstring>
</title>
<catalogentry>
<catalog>nl.wur.wurtv</catalog>
<entry>
<langstring>
<value>340</value>
<language>x-none</language>
</langstring>
</entry>
</catalogentry>
<grouplanguage>en</grouplanguage>
<description>
<langstring>
<value>Sponge Culture: Learning from Biology and Ecology</value>
<language>en</language>
</langstring>
</description>
</general>
<metametadata >
<identifier>
<entry>340</entry>
</identifier>
<identifier>
<catalog>oai</catalog>
<entry>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</entry>
</identifier>
<contribute>
<date>
<dateTime>2001-12-01T00:00:00.00Z</dateTime>
</date>
</contribute>
<contribute>
<role>
<source>PROJECT1.0</source>
<value>provider</value>
</role>
<entity>
BEGIN:VCARD User VERSION:3.0 END:VCARD
</entity>
<date>
<dateTime>2001-10-10T15:56:17.58Z</dateTime>
</date>
</contribute>
<metadatascheme>LORENET</metadatascheme>
</metametadata>
</lom>
</metadata>
</relatedData>
</action>
</event>
</events>
</item>
</feed>
</group>
</metadata>
</record>
<record>
<!-- similar other records that are distnguished with unique id's (guid element) -->
</record>
</ListRecords>

The oupt file should be:

<?xml version="1.0" encoding="UTF-8" ?>
<ListRecords>
<record>
<dc:header>Project_DEM_100</dc:header>
<dc:date>2000-02-14T09:23:25Z</dc:date>
<metadata>
<group xsi:noNamespaceSchemaLocation="http://url.for.schema/schema.xsd">
<dc:title>USER.765</dc:title>
<dc:feedData>
<dc:title>My feed</dc:title>
<dc:url>no.url.available</dc:url>
<dc:item>
<!-- Here identifier is the unique id for each of the records and guid element is changed into identifier element -->
<dc:identifier>oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</dc:identifier>
<dc:events>
<dc:event>
<dc:dateTime>2000-03-26T13:27:49.00</dc:dateTime>
<dc:userAction>
<dc:actionType>doSomeAtcion</dc:actionType>
<dc:relatedData>
<metadata>
<lom xsi:schemaLocation="http://ltsc.ieee.org/xsd/LOM">
<general >
<dc:identifier>340</dc:identifier>
<identifier>
<dc:identifier>oa1,oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</identifier
<dc:title>Graduation mw. S. de Caralt</dc:title>
<dc:catalogentry>
<dc:catalog>nl.wur.wurtv</dc:catalog>
<dc:language>x-none</dc:language>
</dc:catalogentry>
<dc:language>en</dc:language>
<dc:description>Sponge Culture: Learning from Biology and Ecology</dc:description>
</general>
<metametadata >
<dc:identifier>340</identifier>
<dc:identifier>oai, oai:triple-l:2c7ba037-52a6-4323-97dd-b6ea1cdbfd18:340</dc:identifier>
<dc:contribute>
<dc:date>2001-10-10T15:56:17.58Z</dc:date>
</dc:contribute>
<dc:contribute>
<dc:role>PROJECT1.0,provide</dc:role>
<entity>
BEGIN:VCARD User VERSION:3.0 END:VCARD
</entity>
<dc:date>2001-10-10T15:56:17.58Z</dc:date>
</dc:contribute>
<dc:metadatascheme>LORENET</dc:metadatascheme>
</metametadata>
</lom>
</metadata>
</dc:relatedData>
</dc:userAction>
</dc:event>
</dc:events>
</dc:item>
</dc:feedData>
</group>
</metadata>
</record>
<record>
<!-- similar other records that are distnguished with unique id's (guid element) and trasnformed into above format -->
</record>
</ListRecords>

I don't know anything about xslt so need help about how this tranformation can be done..
Thnx. & regards..
 
Old March 3rd, 2009, 10:11 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Try an XSLT tutorial if you don't know anything about XSLT. You seem to want to copy some elements from the input to the output, for others you seem to want to change the name. Here is an example doing that for the first few elements in your XML input, you will need to add (a lot of) templates mapping the remainng elements:
Code:
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:dc="http://example.com/dc"
  version="1.0">
  
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  
  <xsl:template match="/ListRecords">
    <ListRecords>
      <xsl:apply-templates select="@* | node()"/>
    </ListRecords>
  </xsl:template>
  
  <xsl:template match="record/header">
    <xsl:apply-templates/>
  </xsl:template>
  
  <xsl:template match="record/header/identifier">
    <dc:header>
      <xsl:apply-templates/>
    </dc:header>
  </xsl:template>
  
  <xsl:template match="record/header/datestamp">
    <dc:date>
      <xsl:apply-templates/>
    </dc:date>
  </xsl:template>

</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog





Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding xml-html transformation of an xml string using xslt and javascript suprakash444 XSLT 1 January 12th, 2009 01:23 AM
creating a subset of xml schema using XSLT kapar_p XSLT 8 November 21st, 2006 09:46 AM
XSLT transformation from XML buffer and XSL file sundaramkumar Javascript 1 September 5th, 2005 02:11 AM
Xml to Xml Transformation using xslt ShaileshShinde XSLT 1 July 20th, 2005 01:20 AM
XML to XML transformation using XSLT karjagis XSLT 3 July 30th, 2004 06:13 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.