Re: [xsl] creating top-level elements from within child elements

Subject: Re: [xsl] creating top-level elements from within child elements
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 22 Feb 2005 15:36:41 GMT
  The problem Im facing with this approach is that I do not want A2 to
  appear i n the output xml file unless some condition in the A1
  template is true. This brings me back to the use of a 'flag' boolean
  variable which will check whether its value is 'true' before creating

If the test affects the generation of both A1 and A2 the just move it up
to the point that you are generating those elements instead of having it
in the template that's just generating A2. really there is no problem

  However it would be much more efficient to have some feature in XSLT
  which will allow you to position an element outside the template.  

templates are the XSLT mechanism for determing where in the result tree
constructed elements are placed. So I have no idea what you mean here.

> I am not sure how you can create the element <SubConcepts> from within 
> the <PrimeConcept> template match. My present code is

this is just the same as generating any other element.

You (still) have

<xsl:template match="/">
       <PrimeConcept><xsl:apply-templates select="Top/TopNode" 

which is explictly wrapping a PrimeConcept around everything, which is
why everything is coming out as a child of PrimeConcept.

You didn't post your input, so this isn't filled in , but you want
something like:

<xsl:template match="Top">
       <xsl:apply-templates select="TopNode" />

<xsl:template match="TopNode">
<PrimeConcept id='10180'>Car</PrimeConcept>
 <SubConcept id='10298'>Toyota</SubConcept>

will do the job, but presumably you want to replace some of those fixed
element and attribute names by xpath expressions.


This e-mail has been scanned for all viruses by Star. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:

Current Thread