XComponent Datasheet (xc0.xco)

Compliant with the XPipe XML Component Architecture (http://xpipe.sourceforge.net)

Template XComponent (For internal XPipe development use)

Documentation

Synopsis

Add child to an given element in xml document using XSLT.

Parameters

ETNForNew
The element type name to use in the added child element(s).
ETNOfAttachPoints
The name of the element type to which child element(s) are to be added.

Description

Find all elements of type ETNOfAttachPoints and adds a child element of type ETNForNew.

Details Summary
Version0.1
Author Sean McGrath
KeyWordsXSLT
Tree Transformation
Element Structure Transformation
ParametersETNForNew :
ETNOfAttachPoints :

Pre
HREFNone
TypeNone
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
BodyNone

Code
TypeXSLT
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

	<xsl:param name="ETNForNew"/>
	<xsl:param name="ETNOfAttachPoints"/>
	

	<xsl:template match="/">
		<xsl:copy>
		<xsl:copy-of select="@*"/>
		<xsl:apply-templates/>
		</xsl:copy>

	</xsl:template>

	<xsl:template match="*">
		  <xsl:choose>
		     <xsl:when test="name()=$ETNForNew">
		     	<xsl:copy>
			       <xsl:element name="{$ETNOfAttachPoints}">
			       </xsl:element>
					<xsl:copy-of select="@*"/>
					<xsl:apply-templates/>
		         </xsl:copy>
		     </xsl:when>

	 	    <xsl:otherwise>
				<xsl:copy>
				<xsl:copy-of select="@*"/>
				<xsl:apply-templates/>
				</xsl:copy>
		     </xsl:otherwise>
		  </xsl:choose>
	</xsl:template>
</xsl:transform>

Post
HREFNone
TypeNone
EncodingPLAIN
ExtractFilenameNone
CLASSPATHNone
BodyNone

Test : First Test
ParametersETNForNew : bar
ETNOfAttachPoints : foo
Input
HREF#UnitTestFile1
EncodingPLAIN
BodyNone
Output
HREF#UnitTestFile2
EncodingPLAIN
BodyNone

Resource : UnitTestFile1
EncodingPLAIN
ExtractFilenameNone
Body

<?xml version="1.0"?>
<test><foo></foo></test>

Resource : UnitTestFile2
EncodingPLAIN
ExtractFilenameNone
Body

<?xml version="1.0"?>
<test><foo><bar/></foo></test>