Search

I am trying to create an entry page that will be loaded via ajax. I need this page to just be a few html elements and not follow the full html, head, body etc.

I can’t seem to get it to output without stripping all my html out.

    <?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" encoding="UTF-8" indent="no"/>
<xsl:template match="/data/tour/entry">
  <img src=""/>
  <h2><xsl:value-of select="title"/></h2>
  <xsl:value-of select="description"/>
 </xsl:template>
</xsl:stylesheet>

From a usability standpoint you shouldn’t be creating pages that require javascript to run.

If you actually go and use progressive enhancement through jQuery’s load() function you can have it isolate an HTML element and pull in that code for you thus solving both problems instantly.

Could you explain that method a little more? I am not too worried about progressive enhancement on this site, more about load times and usability. Warnings are in place so users would understand why the site’s content isn’t loading.

For now, I am more interested in why my html tags are getting stripped.

They are getting stripped because value-of gets the text value of the node, ie. it doesn’t respect the nodes.

Try xsl:copy-of.

@brendo

value-of appears to be working how I would expect. There are no html tags I am trying to pull from the xml, it’s the entire template that is stripping the html surrounding my value-of tags.

Do you mean the HTML from your master template?

<xsl:import href="../utilities/master.xsl"/>

Edit: But then again you said you didn’t want the full HTML stuff… Can you show us what you’re getting and what you were expecting to get?

@Jaasum: The method is actually pretty simple. You have your links work as they normally would and then you hijack them with AJAX to pull in your content.

For example, you could look for every link with a class of ajax and then use the jQuery Load function to pull in the content instead of loading it normally. This function allows you to add a hash tag to the end of the URL to specify what element specifically.

Don’t forget to add return false; to your scripts so they don’t try to load via AJAX and go to the page. The real benefit of this method is it doesn’t require javascript so if someone doesn’t have it they’re not locked out of your site.

@dougoftheabaci: That is exactly what I am doing. Thanks for clarifying :)

@phoque: Here is what I am expecting the above template to output (I realize that the description will need to be copy-of instead of value-of if it contains html)

   <img src="myimage.jpg" />
  <h2>My Heading</h2>
  <p>Here is the description</p>

Here is what it is actually outputting in the source view.

    Tour

        Dummy Entry 1
        Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu. In enim justo, rhoncus ut, imperdiet a, venenatis vitae, justo. Nullam dictum felis eu pede mollis pretium. Integer tincidunt.

            no-image.jpg

Does that help?

<?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" encoding="UTF-8" indent="no"/>

    <xsl:template match="/">
        <xsl:apply-templates select="data/tour/entry" />
    </xsl:template>

    <xsl:template match="/data/tour/entry">
        <img src=""/>
        <h2><xsl:value-of select="title"/></h2>
        <xsl:value-of select="description"/>
    </xsl:template>

</xsl:stylesheet>

@phoque: That worked perfectly. I think this ties into my other thread about extra content getting output.

I am having a hard time wrapping my head around why you have to match “/” then you have to select and match “data/tour/entry” with “/data/tour/entry”. I saw this in the tutorials and I guess I am thinking, “Why not just go straight for what I am getting at?” as in, “Why add the extra step?”.

You have to think of XSLT more like “walking around in my XML tree”. You start with the root and then decide how you want to descend.

Your parser can’t ignore parts of the XML tree by itself. You have to tell him to do that by giving him an apply-templates with a specific select expression (you might also use apply-templates without the select-attribute, it will simply use the next child-element available)

So always start with "/" (in most cases it’s in your master.xsl). From there on you can select anything you want.

Edit: It’s actually quite hard to explain… :-)

Well then, why does my master.xsl output html just fine starting from match=”/”

Because the template that matches / has all the HTML in it. Have you had a look at the default workspace that comes with Symphony?

I haven’t looked at the default workspace, but I have gone through the tutorials.

I haven’t looked at the default workspace, but I have gone through the tutorials.

I suggest you do both.

I will, thanks for your help and advice.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details