Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A very simple answer. But I dont get it

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Look at this files, please, and tell me why the title of page it is shown also on the html page.

I have an xml files like that:
<root>
<page>
<title>asta la vista baby
</tile>
<overview>
<head>
<field1>..</field1>
<field2>..</field2>
</head>
<list>
<row>
<field1>..</field1>
<field2>..</field2>
</row>
</list>
</overviw>
</page>
</root>

and when I add the xsl files like this:

<?xml version=&quot;1.0&quot;?>
<xsl:transform
version=&quot;1.0&quot;
xmlns:xsl=&quot;
<xsl:eek:utput method=&quot;html&quot; indent=&quot;no&quot;/>

<xsl:template match=&quot;/&quot;>


<html>
<xsl:apply-templates/>
</html>
</xsl:template>

<xsl:template match=&quot;page&quot;>
<head>
<title><xsl:value-of select=&quot;title&quot;/></title>
<link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;table.css&quot; title=&quot;Style&quot;/>
</head>
<body>

<xsl:apply-templates/>

</body>

</xsl:template>

<xsl:template match=&quot;overview&quot;>
<table>
<xsl:apply-templates/>
</table>
</xsl:template>

<xsl:template match=&quot;head&quot;>
<tr class=&quot;header&quot;>
<td><xsl:value-of select=&quot;field1&quot;/></td>
<td><xsl:value-of select=&quot;field2&quot;/></td>
</tr>
</xsl:template>

<xsl:template match=&quot;row[position() mod 2 = 1]&quot;>
<tr class=&quot;odd&quot; style=&quot;cursor:hand&quot; >
<td><xsl:value-of select=&quot;field1&quot;/></td>
<td><xsl:value-of select=&quot;field2&quot;/></td>
</tr>
</xsl:template>

<xsl:template match=&quot;row&quot;>
<tr class=&quot;even&quot; style=&quot;cursor:hand&quot;>
<td><xsl:value-of select=&quot;field1&quot;/></td>
<td><xsl:value-of select=&quot;field2&quot;/></td>
</tr>
</xsl:template>

</xsl:transform>
Maybe you have some other idee of how can I manipulate form, action of button, from xml to xsl.
 
ok it's to do with the apply-templates.

when you call apply-templates it looks at your current position (ie. what node you're at) and then searches for templates for all the children of that.

in between your <body> tags you call apply-templates where your current position is at /root/page - so if you look at all the children you have <overview> AND <title>

so the xsl processor tries to find a match for <title> as well as <overview>. in xsl if there is no match then it effectively takes off the tags and processes the contents of the tag. so it sees <title>MyTitle</title> - tries to find a template for title, doesn't find one so takes MyTitle and works on that and then because there are no more tags to match it just outputs MyTitle in the output.
for this reason you could also take out the first template for &quot;/&quot; and add the <html> tags into template &quot;page&quot; - so it won't match &quot;/&quot; or &quot;root&quot; so it will throw these away.

one solution would be to instead call <apply-templates select=&quot;overview&quot;/> so only overview is processed.
 
Yes that was! thank you. I'm just at begining of using xml and xsl. I have a lot of jsp files and I want to connect its to only one very costumizing xsl file.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top