Subsonic API XML transformation with XSLT in dreamweaver?

Need help? Post your questions here.

Moderator: moderators

Subsonic API XML transformation with XSLT in dreamweaver?

Postby rthomas » Mon Dec 13, 2010 12:58 pm

I use the serverside (PHP) XML/XSL tranformation class in Dreamweaver to transform the xml generated output from the subsonic rest api on the fly with a xslt stylesheet to generate data output.

Facts:
    I have a connection with the API and it returns the xml,
    the xml generated by subsonic isn't recognized by the transform class in dreamweaver and results in no data output,
    I tested the source code of the generated xml in a validator and it validates the xml OK,
    If I read the W3C tutorials about xml it says that each element should have a opening and closing tag. It is not allowed to have a single closing tag like the ones used in the subsonic xml,
    If I change it manually from a single closing tag to a seperate opening and closing tag like <album></album> it gives me the right data output,
    the MM_XSLTransform.class.php is in the right directory named includes and placed on the serverside.


For example if I call the api with the url: http://serverip.org:4040/rest/getAlbumL ... 4.0&c=kako
I get the following subsonic-response in xml:


Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<subsonic-response xmlns="http://subsonic.org/restapi" status="ok" version="1.4.0">
  <albumList>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f576f726c64204d616368696e65" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="World Machine" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f576f726c64204d616368696e652f303120576f726c64204d616368696e652e6d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5475726e204974204f6e" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="Turn It On" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5475726e204974204f6e2f3031204265657a6572204f6e652e6d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5472756520436f6c6f757273" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="True Colours" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5472756520436f6c6f7572732f303120546865204368616e742048617320426567756e2e6d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f54686520556c74696d61746520436f6c6c656374696f6e20446973632032" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="The Ultimate Collection Disc 2" isDir="true" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f54686520556c74696d61746520436f6c6c656374696f6e20446973632031" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="The Ultimate Collection Disc 1" isDir="true" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5468652052656d69786573" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="The Remixes" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5468652052656d697865732f3031205468652053756e20476f657320446f776e20284c6976696e67204974205570292e6d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5468652050757273756974206f66204163636964656e7473" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="The Pursuit of Accidents" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5468652050757273756974206f66204163636964656e74732f303120576561766520596f7572205370656c6c2e6d7033" artist="Level 42"/>

    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f546865204561726c79205461706573" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="The Early Tapes" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f546865204561726c792054617065732f30312053616e6473746f726d2e6d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f53746172696e67206174207468652053756e" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="Staring at the Sun" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f53746172696e67206174207468652053756e2f30312048656176656e20696e204d792048616e64732e4d7033" artist="Level 42"/>
    <album id="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5374616e64696e6720696e20746865204c69676874" parent="2f632f6d656469612f4d757369632f506f702f4c6576656c203432" title="Standing in the Light" isDir="true" coverArt="2f632f6d656469612f4d757369632f506f702f4c6576656c2034322f5374616e64696e6720696e20746865204c696768742f303120546865204d6963726f204b69642e6d7033" artist="Level 42"/>
  </albumList>
</subsonic-response>


In the above example you see that some elements have opening and closing tags but the element album is a single closing tag!

Beneath you see the code for the two files for the processing.

The stylesheet xls:
Code: Select all
<?xml version="1.0" encoding="utf-8"?><!-- DWXMLSource="http://serverip:4040/rest/getAlbumList.view?type=newest&u=xxxx&p=xxxx&v=1.4.0&c=kako" -->
<!DOCTYPE xsl:stylesheet  [
   <!ENTITY nbsp   " ">
   <!ENTITY copy   "©">
   <!ENTITY reg    "®">
   <!ENTITY trade  "™">
   <!ENTITY mdash  "—">
   <!ENTITY ldquo  "“">
   <!ENTITY rdquo  "”">
   <!ENTITY pound  "£">
   <!ENTITY yen    "¥">
   <!ENTITY euro   "€">
]>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<table width="100%" border="1" cellspacing="2" cellpadding="2">
  <tr>
    <th>Artiest/Band</th>
    <th>Titel Album</th>
    <th>CD Cover</th>
  </tr>
 
 
    <xsl:for-each select="subsonic-response/albumList/album">
      <tr>
        <td><xsl:value-of select="@artist"/></td>
        <td><xsl:value-of select="@title"/></td>
        <td><xsl:value-of select="@coverArt"/></td>
      </tr>
    </xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>


The serverside php script:
Code: Select all
<?php
//XMLXSL Transformation class
require_once('includes/MM_XSLTransform/MM_XSLTransform.class.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>albums_recent</title>
</head>

<body>
<?php
$mm_xsl = new MM_XSLTransform();
$mm_xsl->setXML("http://serverip:4040/rest/getAlbumList.view?type=newest&u=xxxx&p=xxxx&v=1.4.0&c=kako");
$mm_xsl->setXSL("albums_recent.xsl");
echo $mm_xsl->Transform();
?>
</body>
</html>


So my questions are:
1 - Why doesn't the xml of the api confirm to the rules?
2 - Is there a way around to do a valid xml/xslt transformation without manually change to xml code?
3 - coverart is returned as binarycode. How to deal with this to make it return as a normal link or imagesource?

PLEASE HELP THIS DESIGNER
Fryslan Boppe!
rthomas
 
Posts: 5
Joined: Sun Jan 24, 2010 10:17 pm
Location: Netherlands

Return to Help

Who is online

Users browsing this forum: No registered users and 20 guests