XSL construct problem

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

XSL construct problem

Post by kendall »

Hello,

i have the following xml file layout

Code: Select all

<album>
<albumtitle>title text<album>
<image src='pathtoimage'/>
<song number="1" play="true">song name</song>
</album>
i am trying to list the songs and link them to windows and real audio files
the link will be dyanimcally built based on the album's image value which is the name of the folder
thus

my xsl file is

Code: Select all

// snippet
<xsl:template match="song">
<li>
<xsl:value-of select="song"/><xsl:apply-templates/>
<xsl:if test="@PLAY='true'"><a><xsl:attribute name="href"><xsl:value-of select="image src attribute value"/><xsl:value-of select="postion()"/></xsl:attribute></a><xsl:text>WIN</xsl:text></xsl:if>
</li>
</xsl:template>
Now as is rite now the code is not finished cause i dont no how to build the link dynamically in xsl

but the syntax for the link would be
html a tag, the word ' albums/',value of image src tag,the word '/track', the song number, the word '.ram or .wma',then the word that acks as the link</a>
im not sure doe how to code this in xsl....anyone knows how or understands what im trying to acheive?

Kendall
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Something like this?

Code: Select all

<xsl:template match="song">
<li>
	<xsl:value-of select="song"/>
	<xsl:apply-templates/>

	<!-- Aint this all case sensitive? ie. @PLAY != @play -->
	<xsl:if test="@play = 'true'">
		<a>
			<xsl:attribute name="href">
				<xsl:text>albums/<xsl:text>
				<!-- Get the image src attribute -->
				<xsl:value-of select="../image/@src"/>
				<xsl:text>/track</xsl:text>
				<xsl:value-of select="postion()"/>
				<!-- How do you know whether it's a .ram or .wma? -->
			</xsl:attribute>
			<!-- Get the song name to use as a link -->
			<xsl:value-of select="." />
		</a>
		<xsl:text>WIN</xsl:text>
	</xsl:if>
</li>
</xsl:template>
(untested by me)

Mac
User avatar
kendall
Forum Regular
Posts: 852
Joined: Tue Jul 30, 2002 10:21 am
Location: Trinidad, West Indies
Contact:

Post by kendall »

twigletmac,

Sorry about the duplicate post....i was having a problem with netscape and the cookies for the forum...i thought i hadnt posted so reposted.

ah....i see your code...i was looking at the "preceding-sibling"...out of curiosity how wuld that have worked?

ohhh.. this is great ....dont really need the position thing as i had a "number attr" to work with hmmmm...i should probably try it but ill stick with it for now

Thanks alot....im now getting into XML....its fun! whooppeeeeee

Kendall
Post Reply