Thanks for your suggestion, I realized that I simplified my original
problem a bit too much. My original problem can't be solved by simply
matching some XPath query. Still this gives me some ideas to try in my
much complicate context.
QCY
On 9/7/06, Mukul Gandhi <gandhi(_dot_)mukul(_at_)gmail(_dot_)com> wrote:
Please try this stylesheet:
<?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="/x">
<Ingredients>
<xsl:for-each select="Spices/Spice | MeatParentTags/Meats/Meat |
Vegetables/Vegetable">
<Ingredient>
<xsl:copy-of select="@*" />
</Ingredient>
</xsl:for-each>
</Ingredients>
</xsl:template>
</xsl:stylesheet>
This when applied to XML:
<?xml version="1.0" encoding="UTF-8"?>
<x>
<Spices>
<Spice name="black pepper" id="11" />
<Spice name="ginger powder" id="12" />
<Spice name="salt" id="13" />
</Spices>
<MeatParentTags>
<Meats>
<Meat name="pork" id="21" />
</Meats>
</MeatParentTags>
<Vegetables>
<Vegetable name="Green Pepper" id="34" />
</Vegetables>
</x>
Produces the desired output:
<?xml version="1.0" encoding="UTF-8"?>
<Ingredients>
<Ingredient name="black pepper" id="11"/>
<Ingredient name="ginger powder" id="12"/>
<Ingredient name="salt" id="13"/>
<Ingredient name="pork" id="21"/>
<Ingredient name="Green Pepper" id="34"/>
</Ingredients>
On 9/7/06, Cherry Yang <qian(_dot_)cherry(_dot_)yang(_at_)gmail(_dot_)com>
wrote:
> Hi all,
> I was not able to find out how to create child elements to existing
> Parent elements after going through my XSLT document and searching on
> the web. I might not be searching with the right key words. Here is my
> problem:
>
> My Source xml document looks something like this:
> <Spices>
> <Spice name="black pepper" id="11"/>
> <Spice name="ginger powder" id="12"/>
> <Spice name="salt" id="13"/>
> </Spices>
> ....
> <MeatsParentTags>
> ......
> <Meats>
> <Meat name="pork" id="21"/>
> </Meats>
> </MeatParentTags>
> .....
> <Vegetables>
> <Vegetable name="Green Pepper" id="34/>
> </Vegetables>
>
> My desired output would be a combination of these tags.
> <Ingredients>
> <Ingredient name="black pepper" id="11"/>
> <Ingredient name="ginger powder" id="12"/>
> <Ingredient name="salt" id="13"/>
> <Ingredient name="pork" id="21"/>
> <Ingredient name="Green Pepper" id="34/>
> </Ingredients>
>
> My XSLT would create element <Ingredients> when processing <Spices>.
> Later on it should only create <ingredient> element as child element
> to <Ingredients> element when processing <Meat> or <Vegetable>. Any
> suggestion on how this can be achieved?
>
> I appreciate your help!
>
> QCY
--
Regards,
Mukul Gandhi
http://gandhimukul.tripod.com
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--