RE: [xsl] passing_cousin_content_as_counter

Subject: RE: [xsl] passing_cousin_content_as_counter
From: mankar@xxxxxxxxxxxxxxx
Date: Sun, 1 Aug 2004 22:40:44 +0300
Hallo Mr Kay,

and first of all let me express my gratitude, since your advice has
been crucial in several occasions.
I used the two templates you sent me in one stylesheet like the one
below:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output indent="yes"/>
<xsl:template match="*">
<xsl:copy><xsl:copy-of select="@*"/><xsl:apply-templates/></xsl:copy>
</xsl:template>
<xsl:template match="COORDINATES_ITEM[position() =
    /SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3 = 0]]">
  <xsl:copy>
    <xsl:text>d</xsl:text>
    <xsl:value-of select="."/>
  </xsl:copy>
</xsl:template>
</xsl:stylesheet>

and while it seems pretty logical to just select the relevant
COORDINATES_ITEM elements
and add a d character in front of their number content, it doesn't.It
produces an identical
xml doc with the source one.It looks like, it ignores the second template
and just applies
the first identity template, producing exactly the same document.

It's true that i had never seen a predicate, like the one used
in the second template, before. It seems that the [position() =
SHAPE/ELEM_INFO/ELEM_INFO_ITEM[position() mod 3 = 0]] is not taken
under consideration at all.

The source xml is:

<?xml version="1.0" encoding="ISO-8859-7"?>
<SHAPE>
 <ELEM_INFO>
      <ELEM_INFO_ITEM>1</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>1001</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>5000</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>7</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>1002</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>5000</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>11</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>5000</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>15</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>1003</ELEM_INFO_ITEM>
      <ELEM_INFO_ITEM>5000</ELEM_INFO_ITEM>
   </ELEM_INFO>
 <COORDINATES>
     <COORDINATES_ITEM>68</COORDINATES_ITEM>
     <COORDINATES_ITEM>54</COORDINATES_ITEM>
     <COORDINATES_ITEM>72</COORDINATES_ITEM>
     <COORDINATES_ITEM>65</COORDINATES_ITEM>
     <COORDINATES_ITEM>83</COORDINATES_ITEM>
     <COORDINATES_ITEM>17</COORDINATES_ITEM>
     <COORDINATES_ITEM>20</COORDINATES_ITEM>
     <COORDINATES_ITEM>60</COORDINATES_ITEM>
     <COORDINATES_ITEM>24</COORDINATES_ITEM>
     <COORDINATES_ITEM>55</COORDINATES_ITEM>
     <COORDINATES_ITEM>98</COORDINATES_ITEM>
     <COORDINATES_ITEM>25</COORDINATES_ITEM>
     <COORDINATES_ITEM>98</COORDINATES_ITEM>
     <COORDINATES_ITEM>25</COORDINATES_ITEM>
<COORDINATES_ITEM>98</COORDINATES_ITEM>
     <COORDINATES_ITEM>25</COORDINATES_ITEM>
   </COORDINATES>
 </SHAPE>

The ELEM_INFO element has 12 exactly children this time and according to
the declared
predicate the values 1,7,11 and 15 of the corresponding 1st, 4th, 7th and
10th ELEM_INFO_ITEM
elements should have been selected in order to pick the 1st,7th,11th and
15th COORDINATES_ITEM
elements and add a d in front of their content.Why do you think the second
isn't the second template taking any affect??

Thank you once more for your valuable time and advice.

Regards
Manousos
Athens

Current Thread