xsl naming variables

Discussion in 'XML' started by sb1, May 7, 2004.

  1. sb1

    sb1 Guest

    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
    sb1, May 7, 2004
    #1
    1. Advertising

  2. Hi,

    (sb1) writes:
    > 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

    --
    Ben Edgington
    Mail to the address above is discarded.
    Mail to ben at that address might be read.
    http://www.edginet.org/
    Ben Edgington, May 7, 2004
    #2
    1. Advertising

  3. sb1

    Andy Fish Guest


    >
    > <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
    Andy Fish, May 7, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. helena

    naming variables in code

    helena, Jan 23, 2005, in forum: Java
    Replies:
    6
    Views:
    356
    Collin VanDyck
    Jan 24, 2005
  2. sagejoshua
    Replies:
    16
    Views:
    643
    Michael Winter
    Nov 9, 2005
  3. Replies:
    1
    Views:
    3,573
    A. Bolmarcich
    May 27, 2005
  4. r holland
    Replies:
    2
    Views:
    508
    r holland
    Jun 4, 2004
  5. Harman
    Replies:
    1
    Views:
    2,483
    Moiristo
    Jul 28, 2006
Loading...

Share This Page