首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >XSLT输出提供额外的<Columns>节点。

XSLT输出提供额外的<Columns>节点。
EN

Stack Overflow用户
提问于 2015-12-16 22:26:16
回答 1查看 67关注 0票数 0

我的最后一个XML应该是以下格式:

代码语言:javascript
运行
复制
<?xml version="1.0" encoding="UTF-8"?>
<Rowsets>
    <Rowset>
        <Columns></Columns>
        <Row></Row>
        <Row></Row>
        <Row></Row>     
    </Rowset>
</Rowsets>

我目前正在合并两个XML,它提供了以下XML:

代码语言:javascript
运行
复制
<?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>

代码语言:javascript
运行
复制
<?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如下:

代码语言:javascript
运行
复制
<?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如下:

代码语言:javascript
运行
复制
<?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>

请帮帮忙。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-12-16 22:50:17

这样试试?

XSLT1.0

代码语言:javascript
运行
复制
<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中修复这个问题,并为自己省去额外转换的需要。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/34323312

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档