Re: [xsl] Confusing namespaces and xslt

Subject: Re: [xsl] Confusing namespaces and xslt
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 2 Oct 2008 21:29:04 +0100
> mode="after" don't work for me.

what did you d these modes, did you get an error (which) or did you get
no error but a result that you didn't want?


There are many ways of adding an element depending on what property of
the source you want to trigger the insertion. 

for example you can do it from the parent, add an element after the
first existing child

<xsl:template match="container">
<xsl:apply-templates select="*[1]"/>
<tape/>
<xsl:apply-templates select="*[position()!=1]"/>
</xsl:template>

Or perhaps yu want every box eleemnt to be followed by a tape, so
instead of the above


  <xsl:template match="box">
   <xsl:copy>
     <!-- Everything here (inside <xsl:copy>) only applies to elements -->
     <xsl:apply-templates select="@*"/>
     <xsl:apply-templates mode="content" select="."/>
     <xsl:apply-templates mode="append" select="."/>
   </xsl:copy>
 <tape/>
  </xsl:template>






> <xsl:template mode=content" match="box">
>   <xsl:element name="box">
>     </xsl:attribute name="width">10</xsl:attribute>
>     </xsl:attribute name="height">8</xsl:attribute>
>   </xsl:element>
>   <xsl:element name="tape>
>   </xsl:element>
> </xsl:template>
> 
> or is there a better way of doing it? One concern is that using the
> above I'm nuking whatever was in box to start with.
> 
as above you can just use apply-templates so that box has the normal
processing in addition to adding tape. there's n need to use xsl:element
unless you need to calculate the element name, if you _did_ want to fix
the attributes as in your example I'd do


<xsl:template mode=content" match="box">
  <box width="10" height="8"/>
  </xsl:element>
</xsl:template>





David

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

Current Thread