bakunin Posted June 23, 2009 Share Posted June 23, 2009 Lets say i have an XML file with 5 Objects in it, object 2 to 5 are childs of Object 1.<Object 1> <childs>-- <Object 2> @type A-- <Object 3> @type B-- <Object 4> @type A-- <Object 5> @type A </childs></Object 1>I have an attribute "type", i want to do a conditional, if the child is of type A then i want to apply the template in the first <p>, if its a type B i want to apply it in the second <p>. <xsl:template match="object"> <p>TYPE A <xsl:apply-templates select="childs"/> </p><p> TYPE B <xsl:apply-templates select="childs"/></p></xsl:template> How should i proceed, i believe i could do a for-each "childs" and then use a conditional in each paragraph but i was wondering if there was a more effective way of doing it. Link to comment Share on other sites More sharing options...
aalbetski Posted June 23, 2009 Share Posted June 23, 2009 <xsl:apply-templates select="//childs[@type=A]"/>and so forthyour XML example needs correction however, for this to really work. Spaces are not allowed in node names. Attributes do not use @ in the name (only when referencing) <Object1> <childs> <Object2 type='A' /> <Object3 type='B' /> <Object4 type='A' /> <Object5 type='A' /> </childs></Object1> Link to comment Share on other sites More sharing options...
bakunin Posted June 23, 2009 Author Share Posted June 23, 2009 Great ! , so i can make a query from apply-template. This is exactly what i wanted to know. I have to say, this website and forum is a very good ressource for XSLT beginners. Very fast answers and always dead on.And yeah about the sample it was not my actual code but a pretty poor representation of it ! Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.