• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

xsl processing

 
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<?xml version="1.0"?><!-- greeting.xml -->
<greeting>
Hello, World!
</greeting>

----------------------------------------
Here's an XSLT stylesheet that defines how to transform the XML document:

<?xml version="1.0"?>
<!-- greeting.xsl -->
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl : output method="html"/>

<xsl:template match="/">
<xsl:apply-templates select="greeting"/>
</xsl:template>

<xsl:template match="greeting">
<html>
<body>
<h1>
<xsl:value-of select="."/>
</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
--------------------------------------------

In the above example greeting.xml is being transformed using greeting.xsl.

My confusion is in <xsl:apply-templates select="greeting"/>. When apply-templates is encountered, xsl will look for the element that is specified in the select and will apply ntemplate to that element. The template that is applied to it is the template below. Does the template below has to be named as "greeting" ? what happens if template below is named something diffrent (say, "hello" instead of greeting) ? will it sttill be applied to this element ?

<xsl:template match="hello">
<html>
<body>
<h1>
<xsl:value-of select="."/>
</h1>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

If the template is named like this, will it still apply to the <xsl:apply-templates select="greeting"/> ? Is it required that whatever element is specified in tha apply-templates section has to be defined below ?

Please explain this, I did a lot of reading, bit did not find convincing answer to the basic confusion.
 
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You didn't say what you read, or what you didn't understand about what you read. So it's pretty hard to explain that. The book I use is quite clear and gives some examples, but if you are learning XSL by googling for tutorials then I'm not surprised you are having trouble.

It appears you are confused by <xsl:template name="QName"> versus <xsl:template match="Pattern">, though. Only one of these forms has a name.
 
nirjari patel
Ranch Hand
Posts: 386
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I was reading xslt , by O'Reilly. Usually these books are clear but this one is very confusing

I have seen <xsl:template match="/"> and <xsl:apply-templates select="template-name" > proper
I did not see <xsl:temaplte name="--" >

These things look confusing without proper explanation. Can you please expalin these syntax or the book which explains this properly ?

thanks
 
Paul Clapham
Marshal
Posts: 28177
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So what do you want me to say? "Read book X and you will understand what it says"?

Of course that's silly. But the fact is that you haven't said what it is that you don't understand. How about if you post an excerpt from the book and explain what you don't understand about it?
 
You got style baby! More than this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic