Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: How would we get xml tags in xsl if we have same element name

From: Martin Honnen <mahotrash@-----.-->
To: 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/


transparent
Print
Mail
Digg
delicious
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent