Re: [xsl] Creating child elements to existing Parent elements

Subject: Re: [xsl] Creating child elements to existing Parent elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 7 Sep 2006 16:49:56 +0100
> 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?

You are thinking too procedurally and assuming a particular execution
order. Rather than assume that the Spice elements (not tags, XSLT has no
access to the tags in the original document) are processed first and
then try to "ammend" the element generated when you come to the Meat
element, just define what the content of Ingredients needs to be,
wherever it comes from the document, something like

<Ingredients>
  <xsl:for-each
  select="/x/Spices/Spice|/x/MeatsParentTags/Meat|/x/Vegetables/Vegetable">
  <Ingredient>
   <xsl:copy-of select="@*"/>
  </Ingredient>
  </xsl:for-each>
</Ingredients>

David

Current Thread