Hi again George and all,
As I mentioned in an earlier post: I'm new to XSL (I've got about 3
hours experience) and am still trying to get my head around it, I have
an XSL file that outputs in CSV format, but when I tried applying it
to the script you sent (below) everything falls down. There are a few
things I don't understand:
- how can I output in CSV format?
- how do I remove the "<AddedAlbums> tag?
- how can I include (for example) "LastChangedBy" labeling it
something else? (eg "User")
An example would be appreciated. This is all a long way from the COBOL
I worked on 20+ years ago!
Thanks again,
Mike in SA
Date: Tue, 20 Jan 2009 10:41:51 +0200
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
From: George Cristian Bina <george(_at_)oxygenxml(_dot_)com>
Subject: Re: [xsl] Re: Re-arranging an XML file
Message-ID: <49758E4F(_dot_)8040904(_at_)oxygenxml(_dot_)com>
Hi Mike,
I do not understand what is the part you have difficulties with. You can
define a key to get the Author elements from their id and then just use
that, see below:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output indent="yes" />
<xsl:key name="artistById" match="Artist" use="Number"/>
<xsl:template match="/">
<xsl:apply-templates select="*/AddedAlbums"/>
</xsl:template>
<xsl:template match="AddedAlbums">
<AddedAlbums><xsl:apply-templates/></AddedAlbums>
</xsl:template>
<xsl:template match="Album">
<Album><xsl:apply-templates/></Album>
</xsl:template>
<xsl:template match="AlbumName">
<AlbumName><xsl:value-of select="."/></AlbumName>
</xsl:template>
<xsl:template match="ArtistNumber">
<Name><xsl:value-of select="key('artistById', .)/Name"/></Name>
</xsl:template>
<xsl:template match="*|text()"/>
</xsl:stylesheet>
Best Regards,
George
--
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Mike Stroud wrote:
Dear Group,
Further to my mail of Date: Tue, 13 Jan 2009: I am still struggling
with this one. Here is an adaptation of a real-world example:
<?xml version="1.0" encoding="UTF-8"?>
<wc:COLLECTION xmlns:wc="http://www.ptc.com/infoengine/1.0">
<DeletedArtists NAME="DeletedArtists" TYPE="Unknown" STATUS="0">
</DeletedArtists>
<AddedArtists NAME="AddedArtists" TYPE="Unknown" STATUS="0">
<Artist>
<LastChangedBy>Mike</LastChangedBy>
<Number>0000000015</Number>
<Name>Bob Dylan</Name>
</Artist>
<Artist>
<LastChangedBy>Mike</LastChangedBy>
<Number>0000000016</Number>
<Name>Bonnie Tyler</Name>
</Artist>
</AddedArtists>
<DeletedAlbums NAME="DeletedAlbums" TYPE="Unknown" STATUS="0">
</DeletedAlbums>
<AddedAlbums NAME="AddedAlbums" TYPE="Unknown" STATUS="0">
<Album>
<ArtistNumber>0000000015</ArtistNumber>
<AlbumNumber>0000000010</AlbumNumber>
<AlbumName>Blood on the Tracks</AlbumName>
</Album>
<Album>
<ArtistNumber>0000000015</ArtistNumber>
<AlbumNumber>0000000011</AlbumNumber>
<AlbumName>Empire Burlesque</AlbumName>
</Album>
<Album>
<ArtistNumber>0000000016</ArtistNumber>
<AlbumNumber>0000000020</AlbumNumber>
<AlbumName>Hide Your Heart</AlbumName>
</Album>
</AddedAlbums>
</wc:COLLECTION>
How can I turn that into something like this using XSL?
<AddedAlbums>
<Album>
<Name>Bob Dylan</Name>
<AlbumName>Blood on the Tracks</AlbumName>
</Album>
<Album>
<Name>Bob Dylan</Name>
<AlbumName>Empire Burlesque</AlbumName>
</Album>
<Album>
<Name>Bonnie Tyler</Name>
<AlbumName>Hide Your Heart</AlbumName>
</Album>
</AddedAlbums>
Many thanks,
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--