[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Problems selecting nodes
Hi,
I have a xml as this one: <?xml version="1.0" encoding="UTF-8"?> <DATOS> <FILTRO> <VER nombre="codVers14" lit="Model" valor="0"/> <AS nombre="aSalon" lit="Annie Modhle" valor="0"/> <COL nombre="codColor" lit="Couleur" valor="0"/> <TAP nombre="codTapizado" lit="Garnissage" valor="0"/> <OPT nombre="codOpciones" lit="OPCIONES" valor="0"/> </FILTRO> <COLORES> <COL cod="C1" lit="Amarillo Heliodoro" ord="1"/> <COL cod="3H" lit="Azul Grand Pavois" ord="1"/> <COL cod="3Y" lit="Azul Lucia" ord="1"/> <COL cod="5K" lit="Azul Mauritius" ord="1"/> <COL cod="5U" lit="Azul Oriental" ord="1"/> <COL cod="J4" lit="Beig" ord="1"/> <COL cod="WP" lit="Blanco Banquise" ord="1"/> <COL cod="4A" lit="Grilyne" ord="1"/> <COL cod="ZR" lit="Gris Aluminio" ord="1"/> <COL cod="YT" lit="Gris Orageux" ord="1"/> <COL cod="W7" lit="Naranja" ord="1"/> <COL cod="XY" lit="Negro Onyx" ord="1"/> <COL cod="X9" lit="Rojo Ardent" ord="1"/> <COL cod="KQ" lit="Rojo Lucifer" ord="1"/> <COL cod="JH" lit="Rojo Postes " ord="1"/> <COL cod="7Z" lit="Verde Hurlevent" ord="1"/> <COL cod="8Y" lit="Verde Lenz" ord="1"/> </COLORES> <VERSIONES> <V14 cod="1CA8A5J6P5..A0" lit="11i Sx Plus" ord="9800009"> <V16 cod="1CA8A5J6P501A031" as="31"> <VEH codcol="3H" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="58H8"/> <VEH codcol="YT" codtap="Z2FT" tap="Z2FT" opt="58H8"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="58H8"/> <VEH codcol="3Y" codtap="Z2FT" tap="Z2FT" opt="58H8"/> <VEH codcol="8Y" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="KQ" codtap="Z2FT" tap="Z2FT" opt="58H8"/> <VEH codcol="KQ" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="3Y" codtap="Z2FT" tap="Z2FT" opt="WL45"/> </V16> </V14> <V14 cod="1CA8A5J7P5..A0" lit="14 Hdi 70cv Sx Plus" ord="9800080"> <V16 cod="1CA8A5J7P501A031" as="31"> <VEH codcol="3H" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="5U" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="7Z" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="8Y" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="8Y" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="J4" codtap="Z2FT" tap="Z2FT" opt="58H9"/> <VEH codcol="J4" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="J4" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="KQ" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="WP" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="X9" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="58H9"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="XY" codtap="Z2FZ" tap="Z2FZ" opt="58H9"/> <VEH codcol="XY" codtap="Z2FZ" tap="Z2FZ" opt="95HC"/> <VEH codcol="YT" codtap="Z2FT" tap="Z2FT" opt="58H9"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="ZR" codtap="Z2FZ" tap="Z2FZ" opt="WL45"/> </V16> <V16 cod="1CA8A5J7P501A030" as="30"> <VEH codcol="3H" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="5U" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="7Z" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="8Y" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="8Y" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="J4" codtap="Z2FZ" tap="Z2FZ" opt="58H9"/> <VEH codcol="J4" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="J4" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="KQ" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="WP" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="X9" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="58H9"/> <VEH codcol="XY" codtap="Z2FT" tap="Z2FT" opt="95HC"/> <VEH codcol="XY" codtap="Z2FZ" tap="Z2FZ" opt="58H9"/> <VEH codcol="XY" codtap="Z2FZ" tap="Z2FZ" opt="95HC"/> <VEH codcol="YT" codtap="Z2FT" tap="Z2FT" opt="58H9"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="58J0"/> <VEH codcol="ZR" codtap="Z2FT" tap="Z2FT" opt="WL45"/> <VEH codcol="ZR" codtap="Z2FZ" tap="Z2FZ" opt="WL45"/> </V16> </V14> </VERSIONES> </DATOS> And with this xsl I obtain the 'selects' that i need: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:param name="v14" select="0"/><!-- 1CA8A5J6P5..A0 1CA8A5J7P5..A0 --> <xsl:param name="as" select="0"/><!-- 30 31 --> <xsl:param name="color" select="0"/> <!-- J4 --> <xsl:param name="tap" select="0"/> <!-- Z2FT Z2FZ --> <xsl:key name="a" match="V16" use="@as"/> <xsl:key name="a1" match="V16" use="concat(../@cod,'+',@as)"/> <xsl:key name="c" match="VEH" use="concat(../../@cod,'+',../@as,'+',@codcol)"/> <xsl:key name="c1" match="VEH" use="concat(../../@cod,'+',@codcol)"/> <xsl:key name="c2" match="VEH" use="concat(../@as,'+',@codcol)"/> <xsl:key name="c3" match="VEH" use="@codcol"/> <xsl:key name="t8" match="VEH" use="concat(../../@cod,'+',../@as,'+',@codcol,'+',@tap)"/> <xsl:key name="t7" match="VEH" use="concat(../../@cod,'+',../@as,'+',@tap)"/> <xsl:key name="t6" match="VEH" use="concat(../../@cod,'+',@codcol,'+',@tap)"/> <xsl:key name="t5" match="VEH" use="concat(../../@cod,'+',@tap)"/> <xsl:key name="t4" match="VEH" use="concat(../@as,'+',@codcol,'+',@tap)"/> <xsl:key name="t3" match="VEH" use="concat(../@as,'+',@tap)"/> <xsl:key name="t2" match="VEH" use="concat(@codcol,'+',@tap)"/> <xsl:key name="t1" match="VEH" use="@tap"/> <xsl:key name="colores" match="COL" use="@cod"/> <xsl:template match="/DATOS"> <table border="0"> <xsl:variable name="clase" select="//LIT/@MARCA"/> <tr> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <xsl:value-of select="//FILTRO/VER/@lit"/> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <select onchange="doCargarVersiones()"> <xsl:attribute name="name"><xsl:value-of select="//FILTRO/VER/@nombre"/></xsl:attribute> <option value="0"> <xsl:value-of select="//LIT/@SELECCIONE"/> </option> <xsl:for-each select="//V14"> <xsl:sort select="@ord" data-type="number" order="ascending"/> <xsl:sort select="@lit" data-type="text" order="ascending"/> <OPTION> <xsl:if test="@cod=$v14"> <xsl:attribute name="selected"/> </xsl:if> <xsl:attribute name="value"><xsl:value-of select="@cod"/></xsl:attribute> <xsl:attribute name="orden"><xsl:value-of select="@ord"/></xsl:attribute> <xsl:value-of select="@lit"/> </OPTION> </xsl:for-each> </select> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <xsl:value-of select="//FILTRO/AS/@lit"/> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <select onchange="doCargarASalon()"> <xsl:attribute name="name"><xsl:value-of select="//FILTRO/AS/@nombre"/></xsl:attribute> <option value="0"> <xsl:value-of select="//LIT/@SELECCIONE"/> </option> <xsl:if test="$v14='0'"> <xsl:apply-templates select="//V14/V16[generate-id()=generate-id(key('a',@as)[1])]/@as"> <xsl:sort select="." order="ascending" data-type="number"/> </xsl:apply-templates> </xsl:if> <xsl:if test="$v14!='0'"> <xsl:apply-templates select="//V14[@cod=$v14]/V16[generate-id()=generate-id(key('a1',concat($v14,'+',@as))[1])]/@as"> <xsl:sort select="." order="ascending" data-type="number"/> </xsl:apply-templates> </xsl:if> </select> </td> </tr> <tr> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <xsl:value-of select="//FILTRO/COL/@lit"/> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <select onchange="doCargarColores()"> <xsl:attribute name="name"><xsl:value-of select="//FILTRO/COL/@nombre"/></xsl:attribute> <option value="0"> <xsl:value-of select="//LIT/@SELECCIONE"/> </option> <xsl:choose> <xsl:when test="$v14='0' and $as='0'"> <xsl:apply-templates select="//COL/@cod"> <xsl:sort select="../@lit" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$v14='0' and $as!='0'"> <xsl:apply-templates select="//COL[@cod = //V14/V16[@as=$as]/VEH[generate-id()=generate-id(key('c2',concat($as,'+',@codcol))[1])]/@codcol]/ @cod"> <xsl:sort select="../@lit" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$v14!='0' and $as='0'"> <xsl:apply-templates select="//COL[@cod = //V14[@cod=$v14]//V16/VEH[generate-id()=generate-id(key('c1',concat($v14,'+',@codcol))[1])]/@codcol]/@cod"> <xsl:sort select="../@lit" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:otherwise> <xsl:apply-templates select="//COL[@cod = //V14[@cod=$v14]/V16[@as=$as]/VEH[generate-id()=generate-id(key('c',concat($v14,'+',$as,'+',@codcol))[1])]/@codcol]/@cod"> <xsl:sort select="../@lit" data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> </select> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <xsl:value-of select="//FILTRO/TAP/@lit"/> </td> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <select> <xsl:attribute name="name"><xsl:value-of select="//FILTRO/TAP/@nombre"/></xsl:attribute> <option value="0"> <xsl:value-of select="//LIT/@SELECCIONE"/> </option> <xsl:if test="$v14='0'"> <xsl:if test="$as='0'"> <xsl:if test="$color='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t1',@tap)[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> <xsl:if test="$color!='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t2',concat($color,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> </xsl:if> <xsl:if test="$as!='0'"> <xsl:if test="$color='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t3',concat($as,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> <xsl:if test="$color!='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t4',concat($as,'+',$color,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> </xsl:if> </xsl:if> <xsl:if test="$v14!='0'"> <xsl:if test="$as='0'"> <xsl:if test="$color='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t5',concat($v14,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> <xsl:if test="$color!='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t6',concat($v14,'+',$color,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> </xsl:if> <xsl:if test="$as!='0'"> <xsl:if test="$color='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t7',concat($v14,'+',$as,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> <xsl:if test="$color!='0'"> <xsl:apply-templates select="//VEH[generate-id()=generate-id(key('t8',concat($v14,'+',$as,'+',$color,'+',@tap))[1])]/@tap"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:if> </xsl:if> </xsl:if> </select> </td> </tr> </table> </xsl:template> <xsl:template match="@as"> <OPTION> <xsl:if test=".=$as"> <xsl:attribute name="selected"/> </xsl:if> <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="."/> </OPTION> </xsl:template> <xsl:template match="//COL/@cod"> <OPTION> <xsl:if test=".=$color"> <xsl:attribute name="selected"/> </xsl:if> <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="../@lit"/> </OPTION> </xsl:template> <xsl:template match="@tap"> <OPTION> <xsl:attribute name="value"><xsl:value-of select="../@codtap"/></xsl:attribute> <xsl:value-of select="."/> </OPTION> </xsl:template> </xsl:stylesheet> Now I want to add another 'select', ('opciones'), if I use the same form to refill it, the number of different combinations it turns almost impossible. There is another form to do it? I tried with something like this: <xsl:key name="o4" match="VEH" use="concat(@codcol,'+',@tap,'+',@opt)"/> <xsl:key name="o3" match="VEH" use="concat(@codcol,'+',@opt)"/> <xsl:key name="o2" match="VEH" use="concat(@tap,'+',@opt)"/> <xsl:key name="o1" match="VEH" use="@opt"/> <!-- ... --> <td> <xsl:attribute name="class"><xsl:value-of select="$clase"/></xsl:attribute> <select> <xsl:attribute name="name"><xsl:value-of select="//FILTRO/OPT/@nombre"/></xsl:attribute> <option value="0"> <xsl:value-of select="//LIT/@SELECCIONE"/> </option> <!--xsl:apply-templates select="//V14[@cod=$v14 or $v14='0']/V16[@as=$as or $as='0']/VEH[generate-id()=generate-id(key('o1',@opt)[1])]/@opt"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates--> <xsl:choose> <xsl:when test="$color!='0' and $tap!='0'"> <xsl:apply-templates select="//V14[@cod=$v14 or $v14='0']/V16[@as=$as or $as='0']/VEH[generate-id()=generate-id(key('o4',concat($color,'+',$tap,'+',@opt))[1])]/@opt"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$color!='0' and $tap='0'"> <xsl:apply-templates select="//V14[@cod=$v14 or $v14='0']/V16[@as=$as or $as='0']/VEH[generate-id()=generate-id(key('o3',concat($color,'+',@opt))[1])]/@opt"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$color='0' and $tap!='0'"> <xsl:apply-templates select="//V14[@cod=$v14 or $v14='0']/V16[@as=$as or $as='0']/VEH[generate-id()=generate-id(key('o2',concat($tap,'+',@opt))[1])]/@opt"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> <xsl:when test="$color='0' and $tap='0'"> <xsl:apply-templates select="//V14[@cod=$v14 or $v14='0']/V16[@as=$as or $as='0']/VEH[generate-id()=generate-id(key('o1',@opt)[1])]/@opt"> <xsl:sort select="." data-type="text" order="ascending"/> </xsl:apply-templates> </xsl:when> </xsl:choose> </select> </td> <!-- ... --> <xsl:template match="@opt"> <OPTION> <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute> <xsl:value-of select="."/> </OPTION> </xsl:template> But it doesn't work in all the cases, some options are absent in the 'select' that they should be there. For example, if i put: <xsl:param name="v14" select="'1CA8A5J7P5..A0'"/><!-- 1CA8A5J6P5..A0 1CA8A5J7P5..A0 --> <xsl:param name="as" select="'31'"/> <xsl:param name="color" select="0"/> <!-- J4 --> <xsl:param name="tap" select="0"/> <!-- Z2FT Z2FZ --> the options in the select must be: 'WL45, 58J0, 95HC, 58H9' but there are only '58J0, 95HC, 58H9'. I hope that someone can help me, and say how to optimize this xsl. Thanks for all. _________________________________________________________________ Latinos en EE.UU: noticias y artmculos de interis para ti http://latino.msn.com/noticias/latinoseneeuu
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|