Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Styling XML

Featured Replies

I'm currently creating a website. I'm creating a section that willd display 3 testimonials, which will randomly display from a selection.

I have got it working using a XML file that holds all of my testimonials. (testimonials are placeholders)

 

I have a couple of questions that I would like to ask the professionals...

 

1 - I would like to style the 'author' to make it bold/different colour/ size etc. I'm struggling to get this working. I've tried adding HTML to it using CDATA and i've tried attaching a CSS stylesheet but none of them work

 

2 - Javascript experts - is it possible to add a line of code so it will never display the same quote at the same time?

 

Please see the attached files. Feel free to edit them and reattach

 

Thanks

Random Testimonial Test.zip

You should be using HTML5 for this not XML. XML is a data interchange format it is not designed to be styled in anyway. XML is also slowly dying away with the newer and much better JSON.

 

As for the testimonials you can just give each one an ID - assuming JSON here:

{
  "testimonials" : [
    "Testimonial 1 lorem ipsum blah blah",
    "Testimonial 2 lorem ipsum blah blah",
    "Testimonial 3 lorem ipsum blah blah",
    "Testimonial 4 lorem ipsum blah blah",
    "Testimonial 5 lorem ipsum blah blah",
    "Testimonial 6 lorem ipsum blah blah"
  ]

}

First you would pull the JSON into an array,

Then you could do a for loop between for the number of testimonials you want printed, in this case 1-> 3,

inside the loop we can call a function to splice the array (remove an item from the array) at an index generated by a random number, the random number in the range of 0 to length of the array.

Return the result, and in my example log it to the console. in yours you will have to inject it into the DOM and style however you choose.

var testimonials = [
    "Testimonial 1 lorem ipsum blah blah",
    "Testimonial 2 lorem ipsum blah blah",
    "Testimonial 3 lorem ipsum blah blah",
    "Testimonial 4 lorem ipsum blah blah",
    "Testimonial 5 lorem ipsum blah blah",
    "Testimonial 6 lorem ipsum blah blah",
    "Testimonial 7 lorem ipsum blah blah",
    "Testimonial 8 lorem ipsum blah blah",
    "Testimonial 9 lorem ipsum blah blah"
  ];


var pullRandomTestimonial = function(arr) {
  var random = Math.floor(Math.random()*arr.length);
  return arr.splice(random,1);
};

for (var i=0; i<3; i++) {
  console.log(pullRandomTestimonial(testimonials));
}

Here's my bin example http://jsbin.com/lofidinuqe/1/edit?js,console

Edited by rbrtsmith

If you want to apply styling to XML it is best to use XSL stylesheets.

 

http://www.xmlfiles.com/xsl/

 

The XML format still has some very good uses and can also be combined with Simple Pie. The main use you see for XML now is for RSS feeds but it is a language that has been very much overlooked in my opinion.

 

Note: if you want to play with XML/XSL you would be best off having Firefox installed if you want to test it locally. Firefox is the only browser with a reliable built in XML parser. For other browsers it may be required to test from a local or remote server.

Edited by nfc212

If you want to apply styling to XML it is best to use XSL stylesheets.

 

http://www.xmlfiles.com/xsl/

 

The XML format still has some very good uses and can also be combined with Simple Pie. The main use you see for XML now is for RSS feeds but it is a language that has been very much overlooked in my opinion.

 

Note: if you want to play with XML/XSL you would be best off having Firefox installed if you want to test it locally. Firefox is the only browser with a reliable built in XML parser. For other browsers it may be required to test from a local or remote server.

 

The main cons of XML vs JSON are the filesize, JSON can transmit the same information much more succinctly, on a large system this could save gigabytes of data. Also with it is very fast to parse epecially if you are using JavaScript where the level of parsing required is minimal.

 

People argue that JSON is also easier to read, and I agree it is for me. However that is pretty subjective and cannot be seen as a real pro for JSON. But if you are using JavaScript heavilly which is the case on most modern web apps it is a lot more straightforward to work with JSON. XML was once very popular JSON has just grown in popularity over the past decade because it's very good at what it does.

 

Clearly there are still uses for XML as many are still using it, but If given the choice of what to use on anything I was developing it would always be JSON, until perhaps something better still was released.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.