XML/XSLT Unclosed meta and link tags

Discussion in 'Web Design and Development' started by zaney, May 5, 2008.

  1. zaney macrumors regular

    Joined:
    Apr 6, 2008
    Location:
    Middle of a field, UK
    #1
    Hi,
    I've recently started using Symphony on my website, and I seem to have got my head round XSLT pretty quick, given that I've never used it before, but I keep hitting one problem: It's returning invalid unclosed meta and link tags in the html.
    Code:
    <?xml version="1.0" encoding="UTF-8" ?>
    
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    
    	<xsl:output method="html" 
    		doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN" 
    		doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
    		omit-xml-declaration="yes"
    		encoding="UTF-8" 
    		indent="yes" />
    
    	<xsl:template match="/">
    		<html>
    			<head>
    				<title><xsl:call-template name="page-title"/></title>
    				<link rel="icon" type="image/gif" href="{$workspace}/img/favicon.gif" />
    				<link rel="stylesheet" type="text/css" media="screen" href="{$workspace}/css/styles.css" />
    				<link rel="alternate" type="application/rss+xml" href="/rss/" />
    			</head>
    That's the start of my XSLT, it works okay, but the self closing link tags, are being stripped of the closing forward slash, and the auto-generated meta tag is also mysteriously devoid of a closing tag.

    Any help would be appreciated, it's nothing serious, but it's bugging the hell out of me.
     
  2. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #2
    I'm not sure what Symphony is, but do you know what XSLT processor it's using? Also, is it being served as XML or HTML? I ran into a similar issue and will look to see what I did exactly to get around it.

    Edit: Not, knowing what language Symphony uses, here's what I do for PHP
    PHP:
       /* load the xml file and stylesheet as domdocuments */
      
    $xsl = new DomDocument();
      
    $xsl->load("recipe_xsl.xsl");
      
    $inputdom = new DomDocument();
      
    $inputdom->load("recipes.xml");
       
    /* create the processor and import the stylesheet */
      
    $proc = new XsltProcessor();
      
    $xsl $proc->importStylesheet($xsl);
      
    $proc->setParameter(null"category""japanese");
       
    /* transform and output the xml document */
      
    $newdom $proc->transformToXml($inputdom);
      echo 
    $newdom;
     
  3. zaney thread starter macrumors regular

    Joined:
    Apr 6, 2008
    Location:
    Middle of a field, UK
    #3
    Symphony is a CMS, it uses XML and XSLT for pretty much everything. I just kinda assumed it'd put out semantically correct XML by default, and that I've done something wrong. I just can't work out what.
    I had to dig about on the site, but I believe it uses LibXSLT, and PHP. Although the PHP is completely hidden from the user, unless you go digging about in the filesystem. Which I guess I might have to do, I was just hoping it was something simple.
     
  4. aLoC macrumors 6502a

    Joined:
    Nov 10, 2006
    #4
    The output method on the XSLT is HTML which is an SGML application, so it's valid to represent an empty element with no trailing slash or close tag. Try changing the output method to xhtml.
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    Change the line from your code to 'xml' (this is what I use) or 'xhtml' (like mentioned above). I missed that piece on my first look.

    Code:
    <xsl:output method="[B]html[/B]"
     
  6. zaney thread starter macrumors regular

    Joined:
    Apr 6, 2008
    Location:
    Middle of a field, UK
    #6
    Thanks for your responses, but I've tried both of these, xml works, but, for some inexplicable reason, still leaves me with unclosed meta and link tags in head. xhtml gives me:
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7
    Not all XSLT processors know how to handle the xhtml method, which is why I use xml instead. It should have worked so may be something with that LibXSLT processor. Have you tried contact the Symphony people? To help narrow the problem you can try doing the XSLT locally. Mac has the xsltproc command that you can use from Terminal. The syntax is:

    xsltproc --novalid -o output.html stylesheet.xsl input.xml

    Make sure you go to the directory where the files are located before using the command. This may help determine if there's an issue with the XSL or with Symphony.
     
  8. aLoC macrumors 6502a

    Joined:
    Nov 10, 2006
    #8
    xhtml output is part of the XSLT 2.0 standard but not 1.0. Sorry, I have been using 2.0 so long I didn't think.
     
  9. zaney thread starter macrumors regular

    Joined:
    Apr 6, 2008
    Location:
    Middle of a field, UK
    #9
    I've looked all over the wiki and forums for Symphony and can find nothing. And ironically this thread is the first result on google when I try and find stuff elsewhere.
    However, I used that xsltproc command and voila. Perfectly formed xml.
    It must be a problem with the XSLT processor it's using, but unfortunately, the Symphony code cannot be modified without permission. Which leaves the possibility that my web host can do something about it. I'm not entirely sure whether you specify a processor, or php's xslt_process (which is what it uses, I dug about a bit in the code, which was hard as it's not commented) just uses a default processor which is controlled by the web host.
    This is the first time I've ever used XSLT, so I'm stumbling about blind here.

    It's okay, like I said above, this is the first time I've used XSLT, so it's a process of trial and error. At least I've narrowed it down a bit to the processor it's using.
     
  10. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #10
    Just curious, what are you using for 2.0? I've used Saxon 9 a little bit for doing some local XSLT, but haven't found a good solution for doing it dynamically from PHP without a bit of overhead. Though I haven't done any searches for a while. I really like the changes in 2.0, has a lot of nice additions and makes some of the stuff I do much easier.
     
  11. zaney thread starter macrumors regular

    Joined:
    Apr 6, 2008
    Location:
    Middle of a field, UK
    #11
    Can I ask what you two use XSLT for?
    I'm currently off work on sick leave, and I've had to drop out of uni, but I'd like to get into web design if possible.
     
  12. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #12
    I use it for a couple things on my web site. I have all of my recipes done in XML and use PHP/XSLT to transform them by category into pages. I've also put all of my artwork in XML form, which points to the location of the image, the title of it, a description, medium, etc. and then similarly have them categorized and use PHP/XSLT to display them in my artwork section. I make use of PHP to pull out file size and image dimensions so I don't have to try and embed that into the XML unnecessarily. I also created a family section on my site in a private area which will show contact information for all of my family and the XML also stores relationship information, so I can show a person and also list their siblings, parents, children, etc. I even create a link around addresses that'll show the address on a Google map. This is done with a mix of XSLT and running through the DOM with PHP. I'm not big on databases so XML gives me a different approach that works well for my situation.

    Off my site I keep all of my personal, professional, and family contact information in XML format (haven't yet created a front-end for it, but I like text editors because I'm just a geek like that). Then I have a couple XSLT files for transforming it into a web page for everyone or by category. I also have a transformation for converting them from XML to vCards, which I can the import into Apple's Address Book application which works wonderfully and it'll update contacts too. Some apps seem to create multiple people when I do that. I also keep a day journal that is in XML format and have a XSLT that lets me view it as a web page.

    I don't really do anything huge with XML as I don't have the need, but find it fun finding ways to use it. I've created a 'single-file' web site (it really involves a couple files, but the content exist in one XML file) with XML and XSL along with JavaScript that is pretty neat. The XSLT transforms the site XML into XHTML and then JavaScript controls which 'page' of the site you're currently viewing. This offers very fast page transitions since everything will be loaded after the initial page loads (which is the down side of it also). This only works for small sites though, and I think it has more potential as something other than for viewing a web site. It'd probably make more sense for a picture gallery type of thing.

    Good luck with messing around with XML and other web design technologies, and hope that sick leave doesn't keep you down.
     
  13. aLoC macrumors 6502a

    Joined:
    Nov 10, 2006
    #13
    The place I work is a Java house anyway, so there's no real overhead in using Saxon (we use version 8). Most of our sites are built with Struts, but one of the frames is the result of an XML pipeline that uses XSLT to transform reusable XML content in to HTML.

    The main benefits (to us) of 2.0 are the regular expressions (which we previously had to do separately in Java or Perl).
     

Share This Page