XSLT Transformation to add multiple not existing child elements

br0nks

New Member
I've got a xml document, looking like this:\[code\]<p> <c1 /> <c2 /></p>\[/code\]The child elements c1 and c2 are optional, but for a processing step I need them to be existent. So I am trying to create a xslt stylesheet to add them as empty elements (the order of the children does not matter).Here is my stylesheet:\[code\]<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy></xsl:template><xsl:template match="p[not(c1)]"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <c1 /> </xsl:copy></xsl:template><xsl:template match="p[not(c2)]"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> <c2 /> </xsl:copy></xsl:template>\[/code\]This works fine, as long as only one of the child elements is missing. But if both are missing, only c1 is created. How do I prevent that and force the creation of both c1 and c2 (and in reality, of about 10 children)?Thanks.Jost
 
Back
Top