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 September 6th, 2010, 06:18 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default transform target file from 2 source files

I have the source file like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<container id="111A" name="DEFAULT HARDDISK">
	<list_of_folder id="listofcontainer_111A">
		<folder id="222A">
			<fileRef>3332</fileRef>
			<fileRef>3333</fileRef>
		</folder>
		<folder id="222B">
			<fileRef>3331</fileRef>
			<fileRef>3335</fileRef>
			<fileRef>3336</fileRef>
			<fileRef>3334</fileRef>
			<fileRef>3337</fileRef>
		</folder>
	</list_of_folder>
	<coreldraw id="3332" name="model1"/>
	<photoshop id="3331" name="model2" />
	<excel id="3336" name="schedule" />	
	<access id="3335" name="program1" />	
	<mp3 id="3333" name="hello song" />	
	<mp4 id="3337" name="pop music" />	
	<wmv id="3334" name="rock rock music" />	
</container>
-----------------
And the second source file, named dictionary.xml file to combine related information for the transformation
Code:
<?xml version="1.0" encoding="UTF-8"?>
<definition id="MANAGE_STORAGE">
	<def id="HARDDISK" class="HARDDISK" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
		<def transform=" size(200 200)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="ABC" transform="rotate(270)">
				<tspan>DEFAULT HARDDISK</tspan>
			</text>
		</def>
		<def id="FOLDERS_$ID" class ="FOLDERS"/>
	</def>
	<def id="FOLDER" class=" FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
		<def transform=" size100 100)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCD" transform="rotate(270)">
				<tspan>DEFAULT FOLDER</tspan>
			</text>
		</def>	
		<def id="GRAPHICS_$ID" class ="GRAPHICS"/>
		<def id="OFFICES_$ID" class ="OFFICES"/>
		<def id="MUSICS_$ID" class ="MUSICS"/>
		<def id="VIDEOS_$ID" class ="VIDEOS"/>			
	</def>
	<def id ='CORELDRAW' class="CORELDRAW">
		<def transform=" size(90 70)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCD" transform="rotate(270)">
				<tspan>CORELDRAW FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='PHOTOSHOP' class="PHOTOSHOP">
		<def transform=" size(90 70)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCWD" transform="rotate(270)">
				<tspan>PHOTOSHOP FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='MP3' class="MP3">
		<def transform=" size(70 70)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BWCD" transform="rotate(270)">
				<tspan>MP3 FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='MP4' class="MP4">
		<def transform=" size(80 90)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="WBCD" transform="rotate(270)">
				<tspan>MP4 FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='WMV' class="WMV">
		<def transform=" size(80 90)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCD" transform="rotate(270)">
				<tspan>WMV FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='ACCESS' class="ACCESS">
		<def transform=" size100 50)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCD" transform="rotate(270)">
				<tspan>ACCESS FILE</tspan>
			</text>
		</def>	
	</def>
	<def id ='EXCEL' class="EXCEL">
		<def transform=" size100 50)"/>
		<def  transform="size(-25,100)" textgroup="yes">
			<text  x="0" y="0" style="BCD" transform="rotate(270)">
				<tspan>EXCEL FILE</tspan>
			</text>
		</def>	
	</def>
</definition>
-------------------
And the target file like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<def id="MANAGE_STORAGE" transform="scale(1)">
	<def id="HARDDISKS" class="HARDDISKS">
		<def id="111A" class="HARDDISK" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
			<def transform=" size(200 200)"/>
			<def  transform="size(-25,100)" textgroup="yes">
				<text  x="0" y="0" style="ABC" transform="rotate(270)">
					<tspan>DEFAULT HARDDISK</tspan>
				</text>
			</def>
			<def id="FOLDERS_111A" class ="FOLDERS">
				<def id="222A" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
						<def transform=" size100 100)"/>
						<def  transform="size(-25,100)" textgroup="yes">
							<text  x="0" y="0" style="BCD" transform="rotate(270)">
								<tspan> FOLDER 1</tspan>
							</text>
						</def>					
						<def id="GRAPHICS_222A" class ="GRAPHICS">
							<def id ='3332' class="CORELDRAW">
								<def transform=" size(90 70)"/>
								<def  transform="size(-25,100)" textgroup="yes">
									<text  x="0" y="0" style="BCD" transform="rotate(270)">
										<tspan>model1</tspan>
									</text>
								</def>	
							</def>												
						</def>
						<def id="OFFICES_222A" class ="OFFICES"/>							
						<def id="MUSICS_222A" class ="MUSICS">
							<def id ='3333' class="MP3">
								<def transform=" size(70 70)"/>
								<def  transform="size(-25,100)" textgroup="yes">
									<text  x="0" y="0" style="BWCD" transform="rotate(270)">
										<tspan>hello song</tspan>
									</text>
								</def>	
							</def>
						</def>
						<def id="VIDEOS_222A" class ="VIDEOS"/>
				</def>			
				<def id="222B" class="FOLDER" drag= "editAttributeDblClk(evt,'$ID');MouseDown(evt);">
					<def transform=" size100 100)"/>
					<def  transform="size(-25,100)" textgroup="yes">
						<text  x="0" y="0" style="BCD" transform="rotate(270)">
							<tspan> FOLDER 2</tspan>
						</text>
					</def>					
					<def id="GRAPHICS_222B" class ="GRAPHICS">
						<def id ='3331' class="PHOTOSHOP">
							<def transform=" size(90 70)"/>
							<def  transform="size(-25,100)" textgroup="yes">
								<text  x="0" y="0" style="BCWD" transform="rotate(270)">
									<tspan>model2</tspan>
								</text>
							</def>	
						</def>						
					</def>
					<def id="OFFICES_222B" class ="OFFICES">
						<def id ='3335' class="ACCESS">
							<def transform=" size100 50)"/>
							<def  transform="size(-25,100)" textgroup="yes">
								<text  x="0" y="0" style="BCD" transform="rotate(270)">
									<tspan>program1</tspan>
								</text>
							</def>	
						</def>
						<def id ='3336' class="EXCEL">
							<def transform=" size100 50)"/>
							<def  transform="size(-25,100)" textgroup="yes">
								<text  x="0" y="0" style="BCD" transform="rotate(270)">
									<tspan>schedule</tspan>
								</text>
							</def>	
						</def>
					</def>
					<def id="MUSICS_222B" class ="MUSICS"/>						
					<def id="VIDEOS_222B" class ="VIDEOS">
						<def id ='3337' class="MP4">
							<def transform=" size(80 90)"/>
							<def  transform="size(-25,100)" textgroup="yes">
								<text  x="0" y="0" style="WBCD" transform="rotate(270)">
									<tspan>pop music</tspan>
								</text>
							</def>	
						</def>
						<def id ='3334' class="WMV">
							<def transform=" size(80 90)"/>
							<def  transform="size(-25,100)" textgroup="yes">
								<text  x="0" y="0" style="BCD" transform="rotate(270)">
									<tspan>rock rock music</tspan>
								</text>
							</def>	
						</def>
					</def>
				</def>
			</def>
			<def id="SHOTCUTS_111A" class ="SHOTCUTS"/>
		</def>
	</def>
</def>


My problem is how to deal with the transformation from 2 source files to 1 target file?
Explane use case: the harddisk contains 2 folders. Each folder contain some files. And the file will be categoried in the specific type of file. For example: mp3 in MUSIC class; mp4 and wmv in VIDEO class; excel and access in OFFICE class; coreldraw and photoshop in graphic class.
The first source file contains just name and id of each element. The second source file defines dictionary of extra information for each element that is presented in first source. And the target file is combination and restructure of source file.

Could anybody help me to deal with this transformation?
I'm in studying XSLT and try to find out the solution for my assignments that are ofcourse difference and also same difficulty level with this exercise.
Thanks

Last edited by metinhoclam; September 6th, 2010 at 06:20 PM..
 
Old September 6th, 2010, 08:41 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Check out the document() function.
 
Old September 7th, 2010, 05:57 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default I have tried

I imagine about <xsl:variable name="dictionary" select="document('dictionary.xml')"/>

But I cannot implement how to connect $ID variable in dictionary file and how to put the elements inside its parent. For example:

def[@graphics]/def[@coreldraw]
def[@graphics]/def[@photoshop]
def[@music]/def[@mp3]
 
Old September 8th, 2010, 02:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

You would look a element up in the dictionary with an XPath that looked like this:

$dictionary//def[@class='WMV']

Note that XML is case sensitive.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old September 8th, 2010, 05:39 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default @sam

But the structure in the dictionary is different with the source file. How can I put the child elements in right its parent?.
For examples: the hierarchical structure of class in dictionary.xml is:
Code:
MANAGE_STORAGE
   + HARDDISK
        + FOLDERS
             + FOLDER
                 +GRAPHICS
                     +CORELDRAW
                     +PHOTOSHOP
                 +OFFICES
                     +ACCESS
                     +EXCEL
                 +MUSICS
                     +MP3
                 +VIDEOS
                     +MP4
                     +WMV
------
I want to know the technique that map the $ID to its parent ID. And populate the childs inside the right parent.


---
Thank for all helping, I need to submit this solution at the end of week? poor me!

Last edited by metinhoclam; September 8th, 2010 at 08:12 AM..
 
Old September 10th, 2010, 01:30 AM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default so, nobody help me...?!!

I think this is the hard exercise, and also complicated.
 
Old September 17th, 2010, 07:22 PM
Authorized User
 
Join Date: Jul 2010
Posts: 27
Thanks: 6
Thanked 0 Times in 0 Posts
Default no, body?!!

why not? anybody help me?
 
Old September 17th, 2010, 07:39 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry you didn't get an answer to your question. I think there are many people like me who will spend about 2 minutes trying to understand a problem and answering it, or if it looks particularly interesting, then they might spend 10-15 minutes. A quick first look at your problem suggests that it will take more than 2 minutes to understand what the problem is, so most of us will turn away and hope that someone else answers it.

Saying that the problem has a deadline doesn't help. Usually if people are under pressure they take less time trying to understand your answer. Many people refuse to answer questions if the questioner appears to be in a hurry.

The lesson is that when posting in a forum like this, you need to reduce the problem to its essentials. There's just far too much detail here. Find a simpler problem with the same characteristics that can be explained on a single screen without scrolling. And try to make it interesting.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Copying Branches From a Source to a Target chernevik XSLT 7 July 19th, 2008 08:46 AM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
Can 1 xslt transform an xml doc into 2 text files Raju Sarode XSLT 7 November 3rd, 2006 04:10 PM
Transform .xsd files to a .xml file lxu XSLT 0 July 19th, 2004 09:23 PM





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