what use does xslt,xpath,xlink,xpointer,dtd have in the real world of application building

1.6k views Asked by At

I am studying all that i can about web services such as soap and found some of the xml displayed on some tutorials hard to understand so i decided to learn from the ground up to make sense of things. xml i already understand so then i saw xpath, xslt, xpath,xquery,xlink, xpointer,xml schema, xsl-fo. there are alot of x related stuff that exists in the xml world. i looked into xslt and dont really see any reason to why it would be used in small or big applications. pretty much of what it is doing can be done with css, javascript/jquery or server side. is xslt even being used? or how about DTD,Xpath,Xquery,Xlink,Xpointer,XSL-Fo,Xforms ?

i do know that xml schema is used with soap unless im wrong.

3

There are 3 answers

4
Samuel Neff On BEST ANSWER

XSLT is a great technology for it's purpose, which is specifically transforming one XML document into another, or sometimes into a plain-text file. If you happen to have data and want to use it to produce HTML or XSL-FO or something else, then XSLT is by far the best way to go. If you're passing XML documents between applications and need to change their format, XSLT is the perfect tool.

However, if your application isn't already using XML, then you probably have no use for it. As a developer, I would recommend learning XSLT because when you do need to do XML transformation it's a great tool to have in your arsenal. In my application we use it in a few places where we have configuration files that get transformed as part of our build process. Besides that though, I haven't used XSLT in years.

XSLT used to be very commonly used on the server to produce HTML. This was particularly the case with traditional ASP back ends largely 'cause traditional ASP was horrible and it was much better to have your business layer produce XML which could then be transformed via XSLT into HTML as opposed to writing ASP code to generate HTML.

Most modern server side environments provide very strong tools for writing dynamic HTML now though so XSLT is less commonly used in this scenario.

As far as comparing XSLT to CSS, there is really no comparison I can see. XSLT is about converting one XML document to another and CSS provides visual styling information for an HTML (or sometimes XML) document.

XPath is very commonly used when working with XML documents and picking out individual pieces of information. It's also heavily used within XSLT.

I've never seen XQuery or XPointer actually used in any of the companies I've worked.

XML Schema is very commonly used for specifying the format of XML documents and validating them. It's heavily used within SOAP Web Services because WSDL utilizes XSD to specify the formats of the SOAP parts.

XSL-FO is for producing PDFs usually. If you want to produce PDFs, this is one way. It technically could be used for other things too, but that's the only use case I'm aware of.

4
Nigel Alderton On

I use XML, XSLT and XQuery as my tools of choice to build websites.

XSLT does what CSS claims to be able to do - separate content from layout.

Say you want to output the HTML for a sales-item;

<div class="salesitem">
   <div class="title">Saucepan</div>
   <a href="images/sp456.jpg">
      <img alt="Saucepan" src="images/sp456.jpg"/>
   </a>
   <div class="price">&#163;19.99</div>
</div>

To output the above using "x" languages, first define the data you want to display. Don't be concerned about layout, appearance or HTML;

<salesitem>
   <title>Saucepan</title>
   <image>sp456.jpg</image>
   <price>19.99</price>
</salesitem>

Then design an XSLT template to turn the above into HTML;

<xsl:template match="salesitem">
   <div class="salesitem">
      <div class="title"><xsl:value-of select="title"/></div>
      <a href="images/{image}">
         <img alt="{title}" src="images/{image}"/>
      </a>
      <div class="price">&#163;<xsl:value-of select="price"/></div>
   </div>
</xsl:template>

Use an XSLT processor to apply the "salesitem" template to the "salesitem" XML and the result will be the HTML you want.

I can't imagine ever going back using response.write ".." or echo ".." to output individual HTML tags. I love the purity of separation that the "x" languages give.

0
Michael Kay On

i looked into xslt and dont really see any reason to why it would be used in small or big applications. pretty much of what it is doing can be done with css, javascript/jquery or server side.

Well, firstly, most of the people using XSLT are indeed using it server side. Client-side XSLT has never really taken off - for some of the reasons, see my paper at XML Prague 2011 (last week) - the main reason is that it's never been available on EVERY browser. I'm hoping to change the situation with a new product Saxon-CE, but I don't want to turn this into an advertisement.

Secondly, the point about XSLT isn't that it can do things that other technologies can't do, it's that it does what it does much more effectively. If you need to transform XML documents into other XML documents or into HTML, XSLT is by far the most effective way of doing it, once you have got up the learning curve. It's true that with the advent of jQuery, doing this in Javascript isn't quite the nightmare it once was, but the declarative rule-based approach of XSLT has many benefits especially when you have to handle change and variety which always exists in both small and large projects.