21

我有以下 XML:

<?xml version="1.0" encoding="utf-8"?>
<Rowsets>
<Rowset>
    <Columns>
        <Column Description="FirstName" MaxRange="1" MinRange="0" Name="FirstName" SQLDataType="12" SourceColumn="FirstName"/>
        <Column Description="LastName" MaxRange="1" MinRange="0" Name="LastName" SQLDataType="12" SourceColumn="LastName"/>
        <Column Description="Phone" MaxRange="1" MinRange="0" Name="Phone" SQLDataType="1" SourceColumn="Phone"/>
    </Columns>
    <Row>
        <FirstName>Michael</FirstName>
        <LastName>David</LastName>
        <Phone>1234567890</Phone>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Michael</LastName>
        <Phone>01234567890</Phone>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <LastName>Christina</LastName>
        <Phone>2345678901</Phone>
    </Row>
    <Row>
        <FirstName>Grey</FirstName>
        <LastName>Meredith</LastName>
        <Phone>3456789012</Phone>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Shepherd</LastName>
        <Phone>5678901234</Phone>
    </Row>
</Rowset>

我想<Phone>从每一行以及从列描述中删除节点。

所以我生成的 XML 如下所示:

<?xml version="1.0" encoding="utf-8"?>
<Rowsets>
<Rowset>
    <Columns>
        <Column Description="FirstName" MaxRange="1" MinRange="0" Name="FirstName" SQLDataType="12" SourceColumn="FirstName"/>
        <Column Description="LastName" MaxRange="1" MinRange="0" Name="LastName" SQLDataType="12" SourceColumn="LastName"/>
    </Columns>
    <Row>
        <FirstName>Michael</FirstName>
        <LastName>David</LastName>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Michael</LastName>
    </Row>
    <Row>
        <FirstName>Yang</FirstName>
        <LastName>Christina</LastName>
    </Row>
    <Row>
        <FirstName>Grey</FirstName>
        <LastName>Meredith</LastName>
    </Row>
    <Row>
        <FirstName>David</FirstName>
        <LastName>Shepherd</LastName>
    </Row>
</Rowset>

我该如何做到这一点?我尝试了各种 XSLT,但我做不到。

4

1 回答 1

34
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*" />

<xsl:template match="@*|node()">
 <xsl:copy>
  <xsl:apply-templates select="@*|node()"/>
 </xsl:copy>
</xsl:template>

<xsl:template match="Column[@SourceColumn='Phone']|Phone" />

</xsl:stylesheet>
于 2012-08-28T04:53:53.403 回答