Altova Mailing List Archives>Archive Index >microsoft.public.xsl Archive Home >Recent entries >Thread Prev - Re: How to get node in the order the xml is given [Thread Next] Re: How to get node in the order the xml is givenTo: NULL Date: 6/29/2009 10:31:00 AM In the example you have provided, it is not the document order which is a cause of concern, rather it is the fact that the immediate childnode of the catalog element is not constant. Such cases are handled via a wildcard based XPath expression or using axes. So, the following expressions will work: a) /catalog/* b) /catalog/child::* c) /catalog/child::node() - Does not work correctly if you have whitespace in the source XML because it also matches whitespace. Neil Smith's example works perfectly and is what you asked for, but rather than a for-each iteration, I would do via a template match: --- <x:template match=3D"/"> <SomeCatalog> <x:apply-templates /> </SomeCatalog> </x:template> <x:template match=3D"catalog/*"> <TheTitle> <x:value-of select=3D"title"/> </TheTitle> </x:template> --- As a side note, I always consider such kind of XML sources to be poorly designed. if you are free to modify the XML source, it would be better put as: --- <catalog> <disk type=3D"cd"> ... <disk type=3D"dvd"> ... <disk type=3D"bluray"> ... </catalog> --- This would avoid the problem of having to use wildcards, altogether. -- Cerebrus. On Jun 28, 5:41=A0pm, naijacoder <luro...@gmail.com> wrote: > hahaha Martin.Sorry for being a pain, > Sorry but i know more than tha tutorial you sent. > I don't think you really understand what 'm trying to achieve > When you said i can use xsl:for-each to be process xml in document > order. > What i'm after is instead of using xsl:apply-templates =A0to match > elements how can i use xsl:for-each > I know i can do > > <catalog> > =A0 =A0 =A0 =A0 <cd> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year> > =A0 =A0 =A0 =A0 </cd> > <cd> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year> > =A0 =A0 =A0 =A0 </cd> > =A0 =A0 =A0 =A0 </catalog> > > <xsl:for-each select=3D"catalog/cd"> > =A0 =A0 =A0 =A0 <tr> > =A0 =A0 =A0 =A0 =A0 <td><xsl:value-of select=3D"title"/></td> > =A0 =A0 =A0 =A0 =A0 <td><xsl:value-of select=3D"artist"/></td> > =A0 =A0 =A0 =A0 </tr> > =A0 =A0 =A0 </xsl:for-each> > > But regarding my own xml the <cd> won't be constant > So i could have > > <catalog> > =A0 =A0 =A0 =A0 <cd> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year> > =A0 =A0 =A0 =A0 </cd> > <dvd> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year> > =A0 =A0 =A0 =A0 </dvd> > <bluray> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <title>Empire Burlesque</title> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <artist>Bob Dylan</artist> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <country>USA</country> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <company>Columbia</company> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <price>10.90</price> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 <year>1985</year> > =A0 =A0 =A0 =A0 </bluray> > =A0 =A0 =A0 =A0 </catalog> > > How can i use xsl:for-each > to process the document order as they come. > I know i'm missing something .... > Thanks Martin > | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
