I have one requierment where i want to remove some tags from xml based on condition.
Here is my input xml:
<?xml version="1.0" encoding="UTF-8"?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<File creation_date="2012-09-20T07:28:47Z" elemId="id280" exportedFileName="sheet 1" last_mod_date="2012-09-20T07:28:48Z" text_flag="8192">
<GSIdentity elemId="id111" label="R0dB1SzBBT4jNA"/>
</File>
<File creation_date="2012-09-20T07:18:26Z" elemId="id283"exportedFileName="test part" last_mod_date="2012-09-20T07:18:26Z" text_flag="8192">
<GSIdentity elemId="id31" label="SIWBFqLyBT4jNA"/>
</File>
<File creation_date="2012-09-20T07:21:03Z" elemId="id322" exportedFileName="test part3" last_mod_date="2012-09-20T07:21:03Z" text_flag="8192">
<GSIdentity elemId="id46" label="ycUBFqLyBT4jNA"/>
</File>
<File creation_date="2012-09-20T07:18:25Z" elemId="id285" exportedFileName="test part2" last_mod_date="2012-09-20T07:18:25Z" text_flag="4096">
<GSIdentity elemId="id29" label="SQRBFqLyBT4jNA"/>
</File>
<Sheet creation_date="2012-09-20T07:28:48Z" date_released="" ead_paragraph="" elemId="id185" keep_limit_prop="3" last_mod_date="2012-09-20T07:28:48Z" object_desc="" object_name="Sheet 1" ref_list="#id111">
<GSIdentity elemId="id112" label="R4WB1SzBBT4jNA"/>
</Sheet>
<PART creation_date="2012-09-20T07:21:22Z" date_released="" ead_paragraph="" elemId="id435" keep_limit_prop="3" last_mod_date="2012-09-20T07:21:28Z" object_name="dwgTest-AA-dwg1" ref_list="#id29 #id31">
<GSIdentity elemId="id32" label="SxZBFqLyBT4jNA"/>
</PART>
<PART creation_date="2012-09-20T07:21:23Z" date_released="2012-09-20T07:21:27Z" ead_paragraph="" elemId="id438" keep_limit_prop="3" last_mod_date="2012-09-20T07:21:29Z" object_name="dwgTest-AA-dwg2" ref_list="#id46">
<GSIdentity elemId="id21" label="itfBFqLyBT4jNA"/>
</PART>
</TCXML>
I want to remove those File tags from this xml which are referred in PART with ref_list tags.
I am trying with following xsl,
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:plm="http://www.tcxml.org/Schemas/TCXMLSchema" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="plm:File">
<xsl:variable name="Ref_List" select="translate(/plm:TCXML/plm:PART/@ref_list,' ','')" />
<xsl:variable name="currentElementGSId" select="plm:GSIdentity/@elemId" />
<xsl:variable name="RefcurrentElementGSId" select="concat(string('#'),$currentElementGSId)" />
<xsl:choose>
<xsl:when test="((contains($Ref_List,$RefcurrentElementGSId))=true())" >
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="@*|node()" />
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Above xsl is working only for one PART in the xml and not all PART tags from the xml , how to loop through all PART tags in the xml.
Thanks for your help in advance.
I am looking for output for this xml as follows,
<?xml version="1.0" encoding="UTF-8"?>
<TCXML xmlns="http://www.tcxml.org/Schemas/TCXMLSchema">
<File creation_date="2012-09-20T07:28:47Z" elemId="id280" exportedFileName="sheet 1" last_mod_date="2012-09-20T07:28:48Z" text_flag="8192">
<GSIdentity elemId="id111" label="R0dB1SzBBT4jNA"/>
</File>
<Sheet creation_date="2012-09-20T07:28:48Z" date_released="" ead_paragraph="" elemId="id185" keep_limit_prop="3" last_mod_date="2012-09-20T07:28:48Z" object_desc="" object_name="Sheet 1" ref_list="#id111">
<GSIdentity elemId="id112" label="R4WB1SzBBT4jNA"/>
</Sheet>
<PART creation_date="2012-09-20T07:21:22Z" date_released="" ead_paragraph="" elemId="id435" keep_limit_prop="3" last_mod_date="2012-09-20T07:21:28Z" object_name="dwgTest-AA-dwg1" ref_list="#id29 #id31">
<GSIdentity elemId="id32" label="SxZBFqLyBT4jNA"/>
</PART>
<PART creation_date="2012-09-20T07:21:23Z" date_released="2012-09-20T07:21:27Z" ead_paragraph="" elemId="id438" keep_limit_prop="3" last_mod_date="2012-09-20T07:21:29Z" object_name="dwgTest-AA-dwg2" ref_list="#id46">
<GSIdentity elemId="id21" label="itfBFqLyBT4jNA"/>
</PART>
</TCXML>
Your input/output do not match your description:
The following XSLT performs an operation equal to that description:
The second template discards any
Fileelement whoseelemIdis found in theref_listattribute of anyPARTelement. All otherFileelements are copied as-is.Note: Your template failed to work as desired because
translateexpects its first argument to be a string; you passed a node list, which was converted to a string according to the following rule: