XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 15 Mar 2007 02:44 AM
Originally Posted: 14 Mar 2007 10:24 AM
Hi all-

Am extremely new to this so please be patient with me---

Am mapping from a clients XML to our XML using stylus and have come up against an interesting issue. It seems that the clients XML refers to another element using reference="" . As i had mentioned, im really very new to XSLT and have racked the condition and instruction info in the help section of Stylus's documentation.

A copy of their xml is below:
<album>
<track>
<contributor reference="CR26272">
<role>Composer</role>
</contributor>
<contributor reference="CE9682">
<role>Main Artist</role>
</contributor>
<contributor reference="CR26272">
<role>Writer</role>
</contributor>
</track>
</album>

=====XML keeps going for each individual <track>====
and then on the bottom....

<contributor id="CE9682">
<name>Bob</name>
</contributor>
<contributor id="CR26272">
<name>Bobs Brother</name>
</contributor>

I want to get the name of the Composer when the role "Composer" is present...... The Track element in the source XML is a repeating element and sometimes the role "Composer" element is present and sometimes not...

It would map to a single Composer attribute in the target xml. <xsl:attribute name="Composer">

Any help in clearing up this probably very easy problem would be greatly appreciated-.

Sorry for the hassle and i hope that my question made sense!




Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 15 Mar 2007 02:45 AM
Any takers?

Postnext
(Deleted User) Subject: Probably simple but....
Author: (Deleted User)
Date: 15 Mar 2007 06:02 AM
Hi Mike,
you can try something like this:

<xsl:for-each select="/album/track/contributor[role = 'Composer']">
<xsl:value-of select="//contributor[@id=current()/@reference]/name"/>
</xsl:for-each>

Hope this helps,
Alberto

Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 15 Mar 2007 10:39 AM
Originally Posted: 15 Mar 2007 10:27 AM
Hi-! Thank you very much for the fast reply. The code was a No go :( As i had said, i really am new to this :( While reading your quick reply helped me learn a little bit, im still stumped....

Below is the full XML that i need to get the info from. On the bottom is ours. I just need to somehow get the name into the composers field on our XML.

<album>
<title>EP</title>
<label_reference>41</label_reference>
<performer>Dj Bob</performer>
<release_date>2006-03-14</release_date>
<upc>8818661</upc>
<catalog_number>Y4P1</catalog_number>
<genre>302</genre>
<disc_count>1</disc_count>
<track_count>2</track_count>
<sent_track_count>2</sent_track_count>
<duration>PT11M31S</duration>
<is_mix>false</is_mix>
<contributor reference="CE10865">
<role>Main Artist</role>
</contributor>
<disc>
<number>1</number>
<track_count>2</track_count>
<sent_track_count>2</sent_track_count>
</disc>
<track>
<title>Nita</title>
<label_reference>O41</label_reference>
<copyright>2006</copyright>
<performer>Dj Bob</performer>
<publisher>Galaxy </publisher>
<isrc>US81</isrc>
<genre>302</genre>
<disc_number>1</disc_number>
<track_number>1</track_number>
<duration>00:05:08</duration>
<explicit_lyrics>false</explicit_lyrics>
<contributor reference="CR30962">
<role>Writer</role>
</contributor>
<contributor reference="CR30962">
<role>Composer</role>
</contributor>
<contributor reference="CE10865">
<role>Main Artist</role>
</contributor>
</track>
<track>
<title>Come </title>
<label_reference>O41</label_reference>
<performer>Dj Bob</performer>
<publisher>Galaxy </publisher>
<isrc>U780</isrc>
<genre>302</genre>
<disc_number>1</disc_number>
<track_number>2</track_number>
<duration>00:06:23</duration>
<explicit_lyrics>false</explicit_lyrics>
<contributor reference="CE10865">
<role>Main Artist</role>
</contributor>
<contributor reference="CR30962">
<role>Writer</role>
</contributor>
<contributor reference="CR30962">
<role>Composer</role>
</contributor>
</track>
</album>
<contributor id="CE10865">
<name>Bob Sapp</name>
</contributor>
<contributor id="CR30962">
<name>Billy Blue</name>
</contributor>
<label id="OR741">
<name>YK</name>
</label>
</submission>




As you can see, the contributor element containing the referred ID CR30962 is on the bottom. Im trying to get Billy Blue (CR30962) to our composer attribute in our XML :(

<document>
<release
title="Groove EP"
labelName="WSB2"
artistName="Bob"
genreId="103"
typeOfRelease="EP"
catalogNumber="WS1"
releaseDate="2007/07/05"
upc="">
<track-list>
<track
title="ght"
mixTitle="Orial"
artistName="Maru"
remixerName=""
isrc="ZA-0021"
composer=""
lyricist="" />
<track
title="Wa Party"
artistName="Mu"
remixerName=""
genreId="103"
price="regular"
length="6:31"
isrc="ZA-"
composer=""
lyricist="" />
</track-list>
</release>
</document>



Sorry for uploading all of this code, but anything that can help you assess the situation better is extremely appreciated. Obviously the problem is that i cant seem to get the referring data in the first XML regarding the tracks composer to match up to our composer attribute field in the second xml. As i had mentioned before, im extremely new to using Stylus Studio and started using it because of the GUI and ease of use for doing simple click and drag xsl:attribute name= -> value of transformations with the mapper.... :(

Postnext
(Deleted User) Subject: Probably simple but....
Author: (Deleted User)
Date: 15 Mar 2007 11:37 AM
Hi Mike,
given the structure of the XML you want to get, this is something that should help. However, I could not find out the mapping for some fields, so you will have to finish the job ;-)

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<document>
<xsl:for-each select="submission/album">
<release title="{title}"
labelName="{/submission/label[@id=current()/label_reference]/name}"
artistName="{performer}"
genreId="{genre}"
typeOfRelease="EP"
catalogNumber="{catalog_number}"
releaseDate="{release_date}"
upc="{upc}">
<track-list>
<xsl:for-each select="track">
<track title="{title}"
mixTitle="Orial"
artistName="{/submission/contributor[@id=current()/contributor[role='Main Artist']/@reference]/name}"
remixerName="{performer}"
isrc="{isrc}"
composer="{/submission/contributor[@id=current()/contributor[role='Composer']/@reference]/name}"
lyricist="{/submission/contributor[@id=current()/contributor[role='Writer']/@reference]/name}"/>
</xsl:for-each>
</track-list>
</release>
</xsl:for-each>
</document>
</xsl:template>
</xsl:stylesheet>

Hope this helps,
Alberto

Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 16 Mar 2007 11:15 AM
Originally Posted: 16 Mar 2007 10:37 AM
Hello Alberto-

Tried and tried to get it to work and didnt have any success :( Have also tried variations on the xpath which you laid out and no luck :( Im sure that this is definately due to my inexperience with xpath etc- Ive summed up their XML below. Im also putting the code that i have used so far-- Thank you for your help!

Summary of their code:

<?xml version="1.0"?>
<submission>
<album>
<track>
<contributor reference="12345">
<role>Writer</role>
</contributor>
<contributor reference="6789">
<role>Composer</role>
</contributor>
</track>
</album>
<contributor id="12345">
<name>Willy</name>
</contributor>
<contributor id="6789">
<name>Bob Sapp</name>
</contributor>
</submission>

Our code which we want to get the 'composer' attribute completed with the Contributors name from each track/contributor/role that is a 'Composer'.

<?xml version="1.0"?>
<document>
<release>
<track-list>
<track composer="" />
<track composer="" />
</track-list>
</release>
</document>


and finally the XSLT that i have tried to implement

<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<document>
<release>
<track-list>
<track>
<xsl:attribute name="composer">
<xsl:for-each select="submission/album/track/contributor [role='Composer']">
<xsl:value-of select="submission/contributor[@id=current()/@reference]/name"/>
</xsl:for-each>
</xsl:attribute>
</track>
</track-list>
</release>
</document>
</xsl:template>
</xsl:stylesheet>




Im really stumped and any help that you can give me will truly be appreciated----------

Thank you so much for your help and in advance for your reply-

M

Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 16 Mar 2007 11:34 PM
Originally Posted: 16 Mar 2007 10:35 PM
Ive also been trying with:

<xsl:attribute name="composer">
<xsl:for-each select="contributor[role='Composer']">
<xsl:value-of select="/submission/contributor[@id=/submission/album/track/contributor[@reference=current()]]/name"/>
</xsl:for-each>
</xsl:attribute>



But no luck so far :(

Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 18 Mar 2007 05:02 AM
Originally Posted: 18 Mar 2007 12:35 AM
Have also been trying with an if clause but still no luck.

<xsl:attribute name="composer">
<xsl:if test="/a:submission/a:album/a:track/a:contributor/a:role = 'Composer'">
<xsl:value-of select="/a:submission/a:contributor[/a:submission/a:album/a:track/a:contributor/@reference = /a:submission/a:album/a:track/a:contributor/@id]/a:name"/>
</xsl:if>
</xsl:attribute>

Postnext
(Deleted User) Subject: Probably simple but....
Author: (Deleted User)
Date: 19 Mar 2007 09:22 AM
Hi Mike,
the XSL you wrote was very different from the one I have posted (it creates a single <track> but then adds all the composers to its value), while the last two examples never look at the current track...

Try starting from this fragment

<xsl:for-each select="submission/album/track/contributor [role='Composer']">

<track>
<xsl:attribute name="composer">
<xsl:value-of select="/submission/contributor[@id=current()/@reference]/name"/>
</xsl:attribute>
</track>

</xsl:for-each>

Hope this helps,
Alberto

Postnext
(Deleted User) Subject: Probably simple but....
Author: (Deleted User)
Date: 20 Mar 2007 05:33 AM
Hi Mike,
I don't understand what is the problem any more.... the XSLT that I wrote a few days ago does exactly this...

Here is the XSLT I wrote:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<document>
<xsl:for-each select="submission/album">
<release title="{title}"
labelName="{/submission/label[@id=current()/label_reference]/name}"
artistName="{performer}"
genreId="{genre}"
typeOfRelease="EP"
catalogNumber="{catalog_number}"
releaseDate="{release_date}"
upc="{upc}">
<track-list>
<xsl:for-each select="track">
<track title="{title}"
mixTitle="Orial"
artistName="{/submission/contributor[@id=current()/contributor[role='Main Artist']/@reference]/name}"
remixerName="{performer}"
isrc="{isrc}"
composer="{/submission/contributor[@id=current()/contributor[role='Composer']/@reference]/name}"
lyricist="{/submission/contributor[@id=current()/contributor[role='Writer']/@reference]/name}"/>
</xsl:for-each>
</track-list>
</release>
</xsl:for-each>
</document>
</xsl:template>
</xsl:stylesheet>

and this is the XML that generates on the data you provided today:

<?xml version="1.0"?>
<document>
<release upc="881034017734" genreId="302" artistName="Stabilizer" typeOfRelease="EP" title="Ambhed" catalogNumber="BBR06" labelName="" releaseDate="2000-03-01">
<track-list>
<track artistName="Stabilizer" mixTitle="Orial" lyricist="Stefan Gohild" composer="Stefan Gohild" remixerName="Stabilizer" title="Ambushed" isrc="USA2P0604519"/>
<track artistName="Stabilizer" mixTitle="Orial" lyricist="Stefan Gohild" composer="Stefan Gohild" remixerName="Stabilizer" title="Wish trol" isrc="USA2520"/>
</track-list>
</release>
</document>

As you can see, the "composer" and the "lyricist" attributes of the "track" element are set to "Stefan Gohild", and the "artistName" is "Stabilizer". You just need to add the code to copy over the rest of the attributes (WAV file, photo, etc..)

Alberto

Postnext
Mike SappSubject: Probably simple but....
Author: Mike Sapp
Date: 20 Mar 2007 10:02 AM
Hi Alberto-

I copied your template and for some reason im not getting any preview data at all when i click on the Preview Result button. All of the code that you have provided me looks fine, but im not sure if is the processor problem or not? Im really stumped...

Do you think it has to do with the declaration?

PS- Thank you VERY VERY much for all of your help so far and your patience with me for being a noob-

Postnext
(Deleted User) Subject: Re: Probably simple but....
Author: (Deleted User)
Date: 20 Mar 2007 10:29 AM
Hi Mike,
have you specified the correct XML source file in the scenario dialog?

Alberto

Postnext
Mike SappSubject: Re: Probably simple but....
Author: Mike Sapp
Date: 20 Mar 2007 10:40 AM
Originally Posted: 20 Mar 2007 10:39 AM
I have.

Also, I can edit the rest of the fields, but if i was to take the exact same code that you supplied and do a re-write (of the xsl file) matching it to another XML (produced by the same source); essentially copying the XSL you provided, i dont get any results....

Also, ive tried running the XSL that you showed me against other files from the same source with no results... The code all looks to make sense and this is why im so stumped-


It always seems to hang at
<?xml version="1.0" encoding="utf-8"?><document/> when displaying the transformed data

Postnext
(Deleted User) Subject: Re: Probably simple but....
Author: (Deleted User)
Date: 20 Mar 2007 11:00 AM
Mike,
if you get just an empty <document> node it means that the first loop in the XSLT (<xsl:for-each select="submission/album">) is not extracting any data. Please verify if the source XML really has a <submission> root node, followed by an <album>; also, verify if these new files are using a default namespace.

Alberto

Postnext
(Deleted User) Subject: Re: Probably simple but....
Author: (Deleted User)
Date: 20 Mar 2007 11:27 AM
Mike,
their namespaces are not "generic"; this XML is the first that shows the namespace attribute xmlns="http://schemas.XXXX.com/XXXXX/XXXXX_1_1.xsd"
This means that the XSLT must have a namespace attribute like xmlns:x="http://schemas.XXXX.com/XXXXX/XXXXX_1_1.xsd" at the <xsl:stylesheet> node, and all the XPath queries like "submission/album" must be changed into "x:submission/x:album".

Alberto

Posttop
Mike SappSubject: Re: Probably simple but....
Author: Mike Sapp
Date: 20 Mar 2007 11:45 AM
Honestly, THANK YOU-. The amount of time that you have helped me learn has more than paid for purchasing stylus-.

Thank you once again for all of your help-

Mike

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.