Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: [xsl] Confusing namespaces and xslt

From: David Carlisle <davidc@--------->
To:
Date: 10/2/2008 8:30:00 PM
> 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. 
________________________________________________________________________


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent