我有一個源XML文件,如下所示:使用XSLT從一個元素添加值到另一個
<section name="Test" code="" type="Table" fundid="15" subtype="SOI1" style="" xmlns="http://composition.bowne.com/2010/v4">
<table xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" accountperiod="2014-07-31" accountperiodtype="0" code="I2" name="Holdings" fundid="15" type="" cols="2">
<colspec colnum="1" colname="1" />
<colspec colnum="2" colname="2" />
<tbody>
<tr type="categoryhead" level="1" itemtype="categoryhead" categorykey="621" hierarchykey="989">
<td colname="1">
<datapoint type="Regular" subtype="" name="Caption" value="Health Care Equipment & Supplies" display="always">Health Care Equipment & Supplies</datapoint>
</td>
<td colname="2">
<datapoint type="Regular" subtype="" name="PercentOfNetAssets" value="16.6" display="always">16.6</datapoint>
</td>
</tr>
<tr type="categoryhead" level="1" itemtype="categoryhead" categorykey="623" hierarchykey="989">
<td colname="1">
<datapoint type="Literal" subtype="Custom" name="All Others*" value="All Others*" display="always">All Others*</datapoint>
</td>
<td colname="2">
<datapoint type="Regular" subtype="" name="PercentOfNetAssets" value="1.5" display="always">[~PONT]1.5[#~PONT]</datapoint> (Line A)
</td>
</tr>
<tr type="otherassets" level="1" itemtype="otherassets" hierarchykey="858">
<td colname="1">
<datapoint type="Literal" subtype="Custom" name="Other Assets" value="Other Assets" display="always">Other Assets</datapoint>
</td>
<td colname="2">
<datapoint type="Regular" subtype="" name="PercentOfNetAssets" value="0.1" display="always">[~PONT]0.1[#~PONT]</datapoint> (Line B)
</td>
</tr>
</tbody>
</table>
</section>
我想這樣做是取[〜PONT]之間的0.1和[#〜PONT ](B行)標記並將其添加到(A行)上的[〜PONT]和[#〜PONT]標記之間的1.5,然後抑制包含(行B)的節點。生成的XML應該是這樣的:
<section name="Test" code="" type="Table" fundid="15" subtype="SOI1" style="" xmlns="http://composition.bowne.com/2010/v4">
<table xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" accountperiod="2014-07-31" accountperiodtype="0" code="I2" name="Holdings" fundid="15" type="" cols="2">
<colspec colnum="1" colname="1" />
<colspec colnum="2" colname="2" />
<tbody>
<tr type="categoryhead" level="1" itemtype="categoryhead" categorykey="621" hierarchykey="989">
<td colname="1">
<datapoint type="Regular" subtype="" name="Caption" value="Health Care Equipment & Supplies" display="always">Health Care Equipment & Supplies</datapoint>
</td>
<td colname="2">
<datapoint type="Regular" subtype="" name="PercentOfNetAssets" value="16.6" display="always">16.6</datapoint>
</td>
</tr>
<tr type="categoryhead" level="1" itemtype="categoryhead" categorykey="623" hierarchykey="989">
<td colname="1">
<datapoint type="Literal" subtype="Custom" name="All Others*" value="All Others*" display="always">All Others*</datapoint>
</td>
<td colname="2">
<datapoint type="Regular" subtype="" name="PercentOfNetAssets" value="1.6" display="always">[~PONT]1.6[#~PONT]</datapoint>
</td>
</tr>
</tbody>
</table>
</section>
我知道我可以使用類似隔離數值:
<xsl:variable name="Value1" select="substring-before(substring-after(string(.),'[~PONT]'),'[#~PONT]')"/>
遺憾的是這就是所有我知道。我很抱歉,如果這個問題看起來很模糊,這是很難解釋的,所以請向我詢問更多細節。提前感謝您的任何建議。順便說一句,我正在使用XSLT版本1。
什麼確切地標識「A線」和「B線」? –