Emerson, Matt wrote:
I have an element <node> which has a certain set of attributes and child
nodes that will always be there. However, it has an additional <list>
child element, that may or may not be present with varying child
elements so <node> could have variations like this...
....
Given these possible variations and based on some processing elsewhere
in the document, I would like to make sure that <node> always has
<item>B</item> in its list...possibly adding <list> if it is not
present.
<xsl:template match="node">
<xsl:copy-of select="@*/>
<xsl:choose>
<xsl:when test="list/item[.='B']">
<!-- ok so far; copy it -->
<xsl:copy-of select="list"/>
</xsl:when>
<xsl:when test="list">
<!-- list exists, but no B item; add it -->
<list>
<xsl:copy-of select="list/node()"/>
<item>B</item>
</list>
</xsl:when>
<xsl:otherwise>
<!-- no list; add it -->
<list>
<item>B</item>
</list>
</xsl:otherwise>
</xsl:choose>
<xsl:apply-templates/>
</xsl:template>
Beware, untested.
J.Pietschmann
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--