Reputation: 113
I have multiple XML files which consist of change tracking attribute or .
Objective:
CT="ACCEPT"
then accept/print all values under <atict:add>
and ignore <atict:del>
values. CT="REJECT"
then accept/print all values with <atict:del>
and ignore <atict:accept>
values.The XML looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<DM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:atict="http://www.arbortext.com/namespace/atict" CT="ACCEPT">
<PARA>abcd
<atict:del>efghi</atict:del>
<atict:add>1456790</atict:add>
</PARA>
</DM>
Desired output XML after processing
<?xml version="1.0" encoding="UTF-8"?>
<DM xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:atict="http://www.arbortext.com/namespace/atict" CT="ACCEPT">
<PARA>abcd 1456790 </PARA>
</DM>
XSLT:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:atict="http://www.arbortext.com/namespace/atict">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform -->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="atict:del[ancestor::DM/@CT='ACCEPT']"/>
<xsl:template match="atict:add[ancestor::DM/@CT='REJECT']"/>
</xsl:stylesheet>
With my XSLT I get the element tags. I only need the values inside the respective tag after processing.
Upvotes: 0
Views: 690
Reputation: 2167
I only need the values inside the respective tag after processing.
Because your identity transform template copy the element once again.
Define yourself two further! templates:
<xsl:template match="atict:del">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="atict:add">
<xsl:apply-templates/>
</xsl:template>
Depending on the internal priority of the templates the xslt processor either takes the "delete"-templates or the (new one) "content-only"-templates.
Upvotes: 1