Generic handling of XML element's children

robertamania

New Member
Assuming we have the following XML...\[code\]<FruitBasket> <Basket> <Apple>1</Apple> <Banana>2</Banana> <Orange>3</Orange> </Basket> <Basket> <Avocado>1</Avocado> <Lemon>2</Lemon> </Basket></FruitBasket>\[/code\]Using a XSLT how would I generate the following transformation?\[code\]<BasketContents> <Content> <FruitName>Apple</FruitName> <FruitAmount>1</FruitAmount> <FruitName>Banana</FruitName> <FruitAmount>2</FruitAmount> <FruitName>Orange</FruitName> <FruitAmount>3</FruitAmount> </Content> <Content> <FruitName>Avocado</FruitName> <FruitAmount>1</FruitAmount> <FruitName>Lemon</FruitName> <FruitAmount>2</FruitAmount> </Content></BasketContents>\[/code\]I would need to do so generically, without knowing what type of fruit is in the basket The xslt would have to handle any child element of "Basket". For instance, I would not know whether the basket contained an apple or avocado, nor would I know how many types of fruit are in the basket.Basically, this breaks down to needing to know how to call the names of child elements, so from the XML's \[code\]<Basket>\[/code\] element, I could possibly apply a template to get the names of it's unknown child elements.Sorry if the analogy is more confusing than helpful.
 
Back
Top