XHTML attribute from XML data?

Show off new creations, get help, or just chat about all aspects of web development and design.

XHTML attribute from XML data?

Postby dissonance on Tue Jun 09, 2009 7:02 am

I have an XML/XSLT combo here that's giving me some trouble. For brevity's sake, I've clipped each down to the relevant sections:
Code: Select all
//derp.xml
<video>
<documentary>
  <network>bbc</network>
  <series>horizon</series>
  <file type="video/avi" md5="cbc869306648e4c9f9fa2f774e1261c8">
    <href>foo/bar.avi</href>
    <width>688</width>
    <height>384</height>
  </file>
</documentary>
</video>

Code: Select all
//derp.xsl
<html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<body>
<xsl:for-each select="video/documentary">

  <xsl:for-each select="file">
    object data=<xsl:value-of select="href"/>
    width=<xsl:value-of select="width"/>
    height=<xsl:value-of select="height"/>
  </xsl:for-each>

</xsl:for-each>
</body>
</html>
Now, the section in question is the one I've blocked out in derp.xsl; the file section.
What I want to do is essentially <object data="<xsl:value-of select="href"/>" width="<xsl:value-of select="width"/>" height="<xsl:value-of select="height"/>"/>, but I know that won't work.
So, long question short, how do I coax data from an XML tag to an XHTML or XSL attribute? How can I get this URI to point an <object> towards my .avi?
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Re: XHTML attribute from XML data?

Postby Blink on Tue Jun 09, 2009 8:24 am

It's been a loooong time since I did XSL but I believe you need to use a variable. So something like:

Code: Select all
<xsl:variable name="example">100</xsl:variable>

<xsl:for-each select="file">
    width="${example}"
 </xsl:for-each>


I'm afraid my memory is a bit too hazy to give you anymore examples but if you search for xsl variables and maybe parms on google you should turn up some stuff you can use.

As I remember you can use a for-each to get the data into a variable from your XML tree and then use that in the loop of your other snippet of code.

Damn, I wish I still knew XSL now.. :-D
User avatar
Blink
Cool 'n that
Cool 'n that
 
Joined: Fri Oct 08, 2004 4:16 pm
Location: UK

Re: XHTML attribute from XML data?

Postby dissonance on Tue Jun 09, 2009 9:21 pm

A little googling, w3c'ing, and irc'ing later, I have it working. Of course Blink knows how to fix it!
Thanks, man.
i had fun once, and it was awful.
User avatar
dissonance
Veteran
Veteran
 
Joined: Wed Oct 10, 2007 12:35 am
Location: usa

Return to Web Design & Development

Who is online

Users browsing this forum: No registered users