Subject: Re: [xsl] variablesAsCounters From: Mukul Gandhi <mukul_gandhi@xxxxxxxxx> Date: Sun, 1 Aug 2004 00:11:43 -0700 (PDT) |
Hi Manousos, Please try the following XSL - <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" indent="yes"/> <xsl:template match="/SHAPE"> <SHAPE> <xsl:copy-of select="ELEM_INFO"/> <xsl:variable name="x" select="ELEM_INFO/ELEM_INFO_ITEM[1]"/> <xsl:variable name="y" select="ELEM_INFO/ELEM_INFO_ITEM[4]"/> <xsl:variable name="z" select="ELEM_INFO/ELEM_INFO_ITEM[7]"/> <COORDINATES> <xsl:for-each select="COORDINATES/COORDINATES_ITEM"> <xsl:choose> <xsl:when test="(position() = $x) or (position() = $y) or (position() = $z)"> <COORDINATES_ITEM> <xsl:value-of select="concat('d',.)"/> </COORDINATES_ITEM> </xsl:when> <xsl:otherwise> <COORDINATES_ITEM> <xsl:value-of select="."/> </COORDINATES_ITEM> </xsl:otherwise> </xsl:choose> </xsl:for-each> </COORDINATES> </SHAPE> </xsl:template> </xsl:stylesheet> Regards, Mukul --- mankar@xxxxxxxxxxxxxxx wrote: > I was wondering if someone could, by the use of one > stylesheet, select the > values of the first, > the fourth and the seventh <ELEM_INFO_ITEM> children > of <ELEM_INFO> > element. Note that the number > of <ELEM_INFO_ITEM> nodes is not predefined.In this > example there are > exactly nine nodes, but > in other cases there might be only three or twelve > etch, but always number > that is multiple of > three. > > I then would like to use the extracted values as > counter values, to apply > counting on > the COORDINATE_ITEM nodeset and select specific > COORDINATE_ITEM elements.In > this example, based > on the extracted values (1, 7 and 11 ), i would like > to select the first, > seventh and eleventh > COORDINATE_ITEM elements content. > > The source xml is the one following: > > <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> > <COORDINATES> > <COORDINATES_ITEM>68</COORDINATES_ITEM> !first > <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> > !seventh > <COORDINATES_ITEM>60</COORDINATES_ITEM> > <COORDINATES_ITEM>24</COORDINATES_ITEM> > <COORDINATES_ITEM>55</COORDINATES_ITEM> > <COORDINATES_ITEM>98</COORDINATES_ITEM> > !eleventh > <COORDINATES_ITEM>25</COORDINATES_ITEM> > <COORDINATES> > </SHAPE> > > Can this be achieved with the use of one and only > stylesheet??The output i > want to generate > should be identical with the source, except for that > the selected > COORDINATE_ITEM elements > will also contain a character like d for example, > concatenated with their > number value.That > last thing is very easy with the use of concat, but > what about the previous > issues.They look > quite heavy programmaticaly for xslt. Should i use > variables?? > > > output xml > > > <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> > <COORDINATES> > <COORDINATES_ITEM>d68</COORDINATES_ITEM> !first > <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>d20</COORDINATES_ITEM> > !seventh > <COORDINATES_ITEM>60</COORDINATES_ITEM> > <COORDINATES_ITEM>24</COORDINATES_ITEM> > <COORDINATES_ITEM>55</COORDINATES_ITEM> > <COORDINATES_ITEM>d98</COORDINATES_ITEM> > !eleventh > <COORDINATES_ITEM>25</COORDINATES_ITEM> > <COORDINATES> > </SHAPE> > > > Regards > Manousos > Athens __________________________________ Do you Yahoo!? Yahoo! Mail Address AutoComplete - You start. We finish. http://promotions.yahoo.com/new_mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] What to use instead of a , Michael Kay | Thread | RE: [xsl] RE: unwanted and non pref, Michael Kay |
Re: [xsl] What to use instead of a , IceT | Date | RE: [xsl] RE: unwanted and non pref, Michael Kay |
Month |