我的最后一个XML应该是以下格式:
<?xml version="1.0" encoding="UTF-8"?>
<Rowsets>
<Rowset>
<Columns></Columns>
<Row></Row>
<Row></Row>
<Row></Row>
</Rowset>
</Rowsets>
我目前正在合并两个XML,它提供了以下XML:
<?xml version="1.0" encoding="UTF-8"?><Rowsets>
<Rowset>
<Columns>
<Column Description="" MaxRange="1" MinRange="0" Name="Material" SQLDataType="1" SourceColumn="Material"/>
<Column Description="" MaxRange="1" MinRange="0" Name="DS_MATERIAL" SQLDataType="1" SourceColumn="DS_MATERIAL"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Press" SQLDataType="1" SourceColumn="Press"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Mold" SQLDataType="1" SourceColumn="Mold"/>
</Columns>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>---</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
</Rowset>
<Rowset>
<Columns>
<Column Description="" MaxRange="1" MinRange="0" Name="Material" SQLDataType="1" SourceColumn="Material"/>
<Column Description="" MaxRange="1" MinRange="0" Name="DS_MATERIAL" SQLDataType="1" SourceColumn="DS_MATERIAL"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Press" SQLDataType="1" SourceColumn="Press"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Mold" SQLDataType="1" SourceColumn="Mold"/>
</Columns>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
</Rowset>
</Rowsets>
现在,由于我只需要一个<Rowset>
和该<Rowset>
中的所有<Row>
,所以我将以下XSLT应用于上面的<Rowset>
:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:java="http://xml.apache.org/xslt/java" exclude-result-prefixes="java" version="1.0">
<xsl:output media-type="text/xml" method="xml"/>
<!-- Merges multiple rowsets -->
<xsl:param name="SD"/>
<xsl:param name="ED"/>
<xsl:param name="RowCount"/>
<xsl:template match="/">
<Rowsets>
<Rowset>
<xsl:copy-of select="/Rowsets/Rowset/Columns"/>
<xsl:for-each select="Rowsets/Rowset">
<xsl:copy-of select="Row"/>
</xsl:for-each>
</Rowset>
</Rowsets>
</xsl:template>
</xsl:stylesheet>
这会在一个<Rowset>
中创建所有的<Rowset>
,但是它会创建两个<Columns>
节点。我只需要一个<Columns>
节点。
以上XSLT的结果XML如下:
<?xml version="1.0" encoding="UTF-8"?><Rowsets>
<Rowset>
<Columns>
<Column Description="" MaxRange="1" MinRange="0" Name="Material" SQLDataType="1" SourceColumn="Material"/>
<Column Description="" MaxRange="1" MinRange="0" Name="DS_MATERIAL" SQLDataType="1" SourceColumn="DS_MATERIAL"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Press" SQLDataType="1" SourceColumn="Press"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Mold" SQLDataType="1" SourceColumn="Mold"/>
</Columns>
<Columns>
<Column Description="" MaxRange="1" MinRange="0" Name="Material" SQLDataType="1" SourceColumn="Material"/>
<Column Description="" MaxRange="1" MinRange="0" Name="DS_MATERIAL" SQLDataType="1" SourceColumn="DS_MATERIAL"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Press" SQLDataType="1" SourceColumn="Press"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Mold" SQLDataType="1" SourceColumn="Mold"/>
</Columns>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>---</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
</Rowset>
</Rowsets>
我的XSLT需要什么修改才能删除这个额外的<Columns>
节点?
我需要的XML如下:
<?xml version="1.0" encoding="utf-8"?>
<Rowsets>
<Rowset>
<Columns>
<Column Description="" MaxRange="1" MinRange="0" Name="Material" SQLDataType="1" SourceColumn="Material"/>
<Column Description="" MaxRange="1" MinRange="0" Name="DS_MATERIAL" SQLDataType="1" SourceColumn="DS_MATERIAL"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Press" SQLDataType="1" SourceColumn="Press"/>
<Column Description="" MaxRange="1" MinRange="0" Name="Mold" SQLDataType="1" SourceColumn="Mold"/>
</Columns>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>111</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>---</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>14</Press>
<Mold>3864F</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>25</Press>
<Mold>4306K-1</Mold>
</Row>
<Row>
<Material>300-6953</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>23</Press>
<Mold>4305P-1</Mold>
</Row>
<Row>
<Material>300-6953-1</Material>
<DS_MATERIAL>222</DS_MATERIAL>
<Press>Summary</Press>
<Mold>---</Mold>
</Row>
</Rowset>
</Rowsets>
请帮帮忙。
发布于 2015-12-16 22:50:17
这样试试?
XSLT1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/Rowsets">
<Rowsets>
<Rowset>
<xsl:copy-of select="Rowset[1]/Columns"/>
<xsl:copy-of select="Rowset/Row"/>
</Rowset>
</Rowsets>
</xsl:template>
</xsl:stylesheet>
我目前正在合并两个XML,它为我提供了后续XML:
您可能可以在合并XSLT中修复这个问题,并为自己省去额外转换的需要。
https://stackoverflow.com/questions/34323312
复制相似问题