RE: [xsl] Trouble with position!

Subject: RE: [xsl] Trouble with position!
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 15 Apr 2005 09:11:49 +0100
>           Looks like this is a bug with the processor(s). This bug is
> listed in the microsoft site in this location.
> http://support.microsoft.com/default.aspx?scid=kb;en-us;324033.
> 
> I got the error using oracle xml parser v2 and xalan as well.

I would have thought it fairly obvious that if three processors give the
same result, then it's likely they are working correctly. As indeed they are
(see my other response).

In any case, the Microsoft bug description clearly states that it applies
when position() is used as an argument to a function call, and there is no
function call here.

But despite the faulty reasoning, the solution below is OK.

Michael Kay
http://www.saxonica.com/

> 
> The following should do the trick.
> 
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> version="1.0">
> 
> <xsl:output method="xml" />
> 
> <xsl:template match="/">
> 
> <xsl:for-each select="/dfile/df_data_row/df_data">
> 
> <xsl:variable name="pos" select="position()"/>
>   <xsl:value-of 
> select="/dfile/df_column_names/df_column[$pos]/@type"/>
> </xsl:for-each>
> 
> </xsl:template>
> 
> </xsl:stylesheet>
> 
> Cheers,
> Omprakash.V
> 
> 
> 
> 
> 
> 
>                                                               
>                                                       
>                     "Adam J                                   
>                                                       
>                     Knight"               To:     
> <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>                                 
>                     <adam@brightid        cc:     (bcc: 
> omprakash.v/Polaris)                                        
>                     ea.com.au>            Subject:     [xsl] 
> Trouble with position!                                 
>                                                               
>                                                       
>                     04/15/2005                                
>                                                       
>                     08:14 AM                                  
>                                                       
>                     Please respond                            
>                                                       
>                     to xsl-list                               
>                                                       
>                                                               
>                                                       
>                                                               
>                                                       
> 
> 
> 
> 
> Hi all,
> 
>  With this xml structure in mind:
>  <dfile>
>   <df_column_names>
>     <df_column name="employee_name" type="hyperlink">Name:</df_column>
>     <df_column name="department" type="text">Department:</df_column>
>     <df_column name="position" type="text">Position:</df_column>
>   </df_column_names>
>   <df_data_row>
>     <data_key>1695</data_key>
>     <df_data>Charles Hilditch</df_data>
>     <df_data>Processing</df_data>
>     <df_data>Mill Supervisor</df_data>
>   </df_data_row>
>  </dfile>
> 
>  I am trying to select the type attribute for a particular 
> df_data element.
> 
>  <xsl:for-each select="./df_data">
>  <xsl:value-of select="/dfile/df_column_names/df_column[position
> ()]/@type"/>
>  </xsl:for-each>
> 
> My algorithm is simply select the type attribute from df_column whose
> position Is equal to current df_data element being processed.
> 
> I keep getting the type attribute for the first db_column name only.
> 
> Thanx to those who respond.
> 
> 
> Cheers,
> Adam
> 
> 
> 
> 
> 
> 
> This e-Mail may contain proprietary and confidential 
> information and is sent for the intended recipient(s) only. 
> If by an addressing or transmission error this mail has been 
> misdirected to you, you are requested to delete this mail immediately.
> You are also hereby notified that any use, any form of 
> reproduction, dissemination, copying, disclosure, modification,
> distribution and/or publication of this e-mail message, 
> contents or its attachment other than by its intended 
> recipient/s is strictly prohibited.
> 
> Visit Us at http://www.polaris.co.in

Current Thread