*
The moose likes XML and Related Technologies and the fly likes xsl processing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "xsl processing" Watch "xsl processing" New topic
Author

xsl processing

nirjari patel
Ranch Hand

Joined: Apr 23, 2009
Posts: 371
<?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.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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

Joined: Apr 23, 2009
Posts: 371
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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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?
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: xsl processing
 
Similar Threads
Question: apply-templates
want to generate wml file from a xsl file
want to generate wml from xsl file
Need help with "Variable"
what is template rule in xsl ?