![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: How would we get xml tags in xsl if we have same element name >Thread Next - Re: How would we get xml tags in xsl if we have same element name Re: How would we get xml tags in xsl if we have same element nameTo: NULL Date: 7/13/2007 1:51:00 PM
kamkaro wrote:
>
> "Martin Honnen" wrote:
>> <xsl:stylesheet
>> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>> version="1.0">
>>
>> <xsl:output method="html" indent="yes"/>
>>
>> <xsl:template match="/">
>> <html lang="en">
>> <head>
>> <title>Example</title>
>> </head>
>> <body>
>> <xsl:apply-templates/>
>> </body>
>> </html>
>> </xsl:template>
>>
>> <xsl:template match="field">
>> <table>
>> <tbody>
>> <tr>
>> <th>Title:</th>
>> <td><xsl:value-of select="title"/></td>
>> </tr>
>> <tr>
>> <th>Identifier = </th>
>> <td><xsl:value-of
>> select="content/table/row/cell/idebtifier"/></td>
>> </tr>
>> <tr>
>> <th>db = </th>
>> <td><xsl:value-of select="content/table/row/cell/db"/></td>
>> </tr>
>> </tbody>
>> </table>
>> </xsl:template>
>>
>> </xsl:stylesheet>
> My question is still there, i have two 'filed' in my xml and according to
> your reply " <xsl:template match="field">" how do i know which field is
> calling ?? I do know if we have different parent name so i can give path
> expression but if we have same parents name so how would we do it, plz
> explain me. thanks in advance.
With that example stylesheet shown above the processor processes the
template for the root node (xsl:template match="/") and creates the HTML
result structure with a html, head, and body element. Then the
xsl:apply-templates processes the child node(s) of the root element and
the built-in templates ensure that processing continues with the
descendant elements. When the processor processes field elements it
finds the template I wrote (xsl:template match="field") and for each
field element creates a table result element. If you want to process
only field elements and want to check which element you process then one
way to achieve that is to explicitly make sure some xsl:apply-templates
selects only field elements, then inside the template you can use the
position() function as follows:
<xsl:template match="/">
<html lang="en">
<head>
<title>Example</title>
</head>
<body>
<xsl:apply-templates select="Record/content/field"/>
</body>
</html>
</xsl:template>
<xsl:template match="field">
<!-- show how position() yields the number -->
<p>Processing field element number <xsl:value-of
select="position()"/></p>
<table>
<tbody>
<tr>
<th>Title:</th>
<td><xsl:value-of select="title"/></td>
</tr>
<tr>
<th>Identifier = </th>
<td><xsl:value-of
select="content/table/row/cell/idebtifier"/></td>
</tr>
<tr>
<th>db = </th>
<td><xsl:value-of select="content/table/row/cell/db"/></td>
</tr>
</tbody>
</table>
</xsl:template>
HTH
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||||
|
