I’m filtering out certain nodes in my XSLT transform, and among those remaining I need to insert a element if a certain sub element is missing.
Here is what I have.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" >
<xsl:output method="xml" indent="yes"/>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="SomeNode">
</xsl:template>
<xsl:template xpath-default-namespace="http://www.tempuri.org" match="TheNode[@type!='SomeType' and @type!='OtherType']">
<!-- If TheNode is missing a child element SomeElement, insert a blank SomeElement element -->
</xsl:template>
</xsl:stylesheet>
Can someone suggest the best way of going about this please?
Thanks.
This transformation:
when applied to this XML document:
produces the wanted, correct result: