[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Copy Child Elements
Alice Wei wrote:
Hi, I assume "and and" meant "and not" ;) When he does that, he won't have any output left (the focus is <reference>, not <refbody>). Actually, though I agree it is usually a bad choice to use //, in his situation it doesn't change the output whether he uses // or refbody/section. However, because // is a very costly operation and it is in not necessary to use it, it should be removed.
Change this to <xsl:apply-templates select="refbody/section" >
Don't use for-each here. Instead, use <xsl:apply-templates select="p" /> and follow up with matching templates like the following. The last one is a so-called throw-away template, it will be called when a <p> matches that did not match any more specific match: <xsl:template match="p[id='Field_ShowAuthorJobTitle']> <dt> <xsl:copy-of select="text() | *" /> </dt> </xsl:template> <xsl:template match="p[id='Desc_ShowAuthorJobTitle']> <dd> <xsl:copy-of select="text() | *" /> </dd> </xsl:template> <!-- throw away other <p> elements --> <xsl:template match="p" /> Your own approach with xsl:if and position() is not necessarily wrong, but it is far harder to create, to maintain and to understand. Using matching templates you let the processor do the math for you. Using copy-of instead of apply-templates in the children of <p> you make sure you copy all elements as well. Using apply-templates does only output the text value if you do not create a matching template for them (this is called an identity copy template). In your case you don't seem to need that, so copy-of suffices. HTH, Cheers, -- Abel Braaksma
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|