I have a source xml file as follows:
<PortfolioStatement xmlns="http://ift.tt/1sr3m0e">
<section xmlns="" name="Schedule of Investments" code="" type="Table" fundid="19" subtype="SOI" style="">
<table xmlns:xsd="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU" accountperiod="2014-10-31" style="SOI_Abbr" accountperiodtype="0" code="Abbreviation" name="Holdings" fundid="19" type="" cols="4">
<colspec colnum="1" colname="1"/>
<colspec colnum="2" colname="2"/>
<colspec colnum="3" colname="3"/>
<colspec colnum="4" colname="4"/>
<tbody>
<tr layoutcode="" type="detail" level="2" itemtype="detail"> (node 1)
<td colname="1">[~ABSYMB]ABC[#~ABSYMB]</td>
<td colname="2">American Depositary Receipt</td>
<td colname="3"/>
<td colname="4"/>
</tr>
<tr layoutcode="" type="detail" level="2" itemtype="detail">
<td colname="1">[~ABSYMB]LP[#~ABSYMB]</td>
<td colname="2">Limited Partnership</td>
<td colname="3"/>
<td colname="4"/>
</tr>
<tr layoutcode="" type="detail" level="2" itemtype="detail">
<td colname="1">[~ABSYMB]REIT[#~ABSYMB]</td>
<td colname="2">Real Estate Investment Trust</td>
<td colname="3"/>
<td colname="4"/>
</tr>
<tr layoutcode="" type="detail" level="2" itemtype="detail"> (node 2)
<td colname="1">[~ABSYMB]DEF[#~ABSYMB]</td>
<td colname="2">Sponsored American Depositary Receipt</td>
<td colname="3"/>
<td colname="4"/>
</tr>
</tbody>
</table>
</section>
</PortfolioStatement>
What I am trying to do is suppress node 1 (as marked) if node 2 exists. Node 1 is defined as having the text 'ABC' in between the tags [~ABSYMB] and [#~ABSYMB] in its child td node. Node 2 is defined as having the text 'DEF' in between the tags [~ABSYMB] and [#~ABSYMB] in its child td node. This would leave the resultant xml looking like this:
<PortfolioStatement xmlns="http://ift.tt/1sr3m0e">
<section xmlns="" name="Schedule of Investments" code="" type="Table" fundid="19" subtype="SOI" style="">
<table xmlns:xsd="http://ift.tt/tphNwY" xmlns:xsi="http://ift.tt/ra1lAU" accountperiod="2014-10-31" style="SOI_Abbr" accountperiodtype="0" code="Abbreviation" name="Holdings" fundid="19" type="" cols="4">
<colspec colnum="1" colname="1"/>
<colspec colnum="2" colname="2"/>
<colspec colnum="3" colname="3"/>
<colspec colnum="4" colname="4"/>
<tbody>
<tr layoutcode="" type="detail" level="2" itemtype="detail">
<td colname="1">[~ABSYMB]LP[#~ABSYMB]</td>
<td colname="2">Limited Partnership</td>
<td colname="3"/>
<td colname="4"/>
</tr>
<tr layoutcode="" type="detail" level="2" itemtype="detail">
<td colname="1">[~ABSYMB]REIT[#~ABSYMB]</td>
<td colname="2">Real Estate Investment Trust</td>
<td colname="3"/>
<td colname="4"/>
</tr>
<tr layoutcode="" type="detail" level="2" itemtype="detail">
<td colname="1">[~ABSYMB]DEF[#~ABSYMB]</td>
<td colname="2">Sponsored American Depositary Receipt</td>
<td colname="3"/>
<td colname="4"/>
</tr>
</tbody>
</table>
</section>
</PortfolioStatement>
The text vales 'ABC' and 'DEF' are setup as parameters. So far my xslt looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:arcml="http://ift.tt/1sr3m0e"
xmlns:fn="http://ift.tt/1fgth28"
xmlns:xsd="http://ift.tt/tphNwY"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:xsi="http://ift.tt/ra1lAU"
exclude-result-prefixes="fn msxml xsl arcml xsd xsi">
<xsl:output indent="yes" method="xml" version="1.0" omit-xml-declaration="no"/>
<!-- Parameters -->
<xsl:param name="Text1">ABC</xsl:param>
<xsl:param name="Text2">DEF</xsl:param>
<!-- Identity template -->
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="tr[td]">
<xsl:choose>
<xsl:when test="substring-before(substring-after(.,'[~ABSYMB]'),'[#~ABSYMB]')=$Text1">
</xsl:when>
<xsl:otherwise>
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
This locates node1 but I don't know how to check for the existence of node2 to perform the match pattern override.
I get the feeling it is probably more confusing to describe my problem than it is to solve it and for that I apologise. Many thanks in advance for any advice anyone has.
No comments:
Post a Comment