xsl naming variables

S

sb1

Hi

I am new to xml and I am trying to use xsl to transform my xml
document to smil.

I want to create a line such as
<video src="../media/countries_video/cuba_100.ram "
id="../media/countries_video/greece_100.ram " region="x"/>

for a number of different video files, the references to which are
held within my xml files. At the minute my code:

<xsl:for-each select="$destination/Country/CountryVideo">

<xsl:variable name="countryvid"
select="$destination/Country/CountryVideo"/>
<video src="{$countryvid}" id="{$countryvid}" region="x" />
</xsl:for-each>

produces the correct number of lines but each contains the reference
to the same file, I'm guessing this is because I can't use the one
variable to reference each. I'd appreciate it if anyone could give me
some pointers on how to get around this. (Bearing in mind I'm very new
to all this!)
Thanks in advance
 
B

Ben Edgington

Hi,

I am new to xml and I am trying to use xsl to transform my xml
document to smil.

I want to create a line such as
<video src="../media/countries_video/cuba_100.ram "
id="../media/countries_video/greece_100.ram " region="x"/>

for a number of different video files, the references to which are
held within my xml files. At the minute my code:

<xsl:for-each select="$destination/Country/CountryVideo">

<xsl:variable name="countryvid"
select="$destination/Country/CountryVideo"/>
<video src="{$countryvid}" id="{$countryvid}" region="x" />
</xsl:for-each>

produces the correct number of lines but each contains the reference
to the same file, I'm guessing this is because I can't use the one
variable to reference each. I'd appreciate it if anyone could give me
some pointers on how to get around this. (Bearing in mind I'm very new
to all this!)

This is a repost of your earlier question. I had a look at that but
wasn't able to get to the bottom of what the problem is. Perhaps if
you could post a small extract of your XML, a bit more of your XSL
and a consistent account of the output you want (the src and id
attributes on your example differ, whereas the XSLT sets them the
same. What do you want?) then we could help.

Ben
 
A

Andy Fish

<xsl:for-each select="$destination/Country/CountryVideo">

<xsl:variable name="countryvid"
select="$destination/Country/CountryVideo"/>
<video src="{$countryvid}" id="{$countryvid}" region="x" />
</xsl:for-each>

inside the <xsl:for-each> the current node (i.e. ".") will be set to the
node you are processing. by referencing $destination/Country/CountryVideo
you are simply referring to the whole node set again. It's like iterating
round a collection object but referring to the whole collection each time
rather than just the current element

Assuming the CountryVideo contains just text, you need something like

<video src="{text()}" id="{text()}">

if the CountryVideo contains attributes, reference them like this

<video src="{@src}">

etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

xsl variables 2
XSL Calculation 0
is it possible to use left angle bracket in xsl 0
XSL : Slow 0
xsl totals composed from variables 5
XSL newbie 1
XSL Grouping 0
xsltproc question - wondering what I did wrong? 4

Members online

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,825
Latest member
VernonQuy6

Latest Threads

Top