0

我正在为一些基本的 XSLT 苦苦挣扎。我想从某些 XML 中删除一个元素,具体取决于它是否没有某个属性(在本例中为 PriorValue)。

XML 看起来像这样 XML 不仅限于以下部分,它还有很多其他部分,并且同样的逻辑也适用于它们。

   <Emp>
       <Personal>
            <First_Name>abc</First_Name>
            <Last_Name>xyz</Last_Name>
            <Gender>1</Gender>
            <Birth_Date PriorValue="1980-08-05">1980-09-05</Birth_Date>
            <Country_of_Birth PriorValue="600">724</Country_of_Birth>
            <Marital_Status PriorValue="0">1</Marital_Status>
        </Personal>
        <Info>
            <Name>abc</Name>
            <ID>Part time</ID>
            <NoOfProbationDays>0</NoOfProbationDays>
            <EMPtype>0</EMPtype>
            <CountryOfBirth PriorValue="IND">ESP</CountryOfBirth>
        </Info>
    </Emp>

所需的 XML 输出如下所示。

    <Emp>
        <Personal>
            <Birth_Date PriorValue="1980-08-05">1980-09-05</Birth_Date>
            <Country_of_Birth PriorValue="600">724</Country_of_Birth>
            <Marital_Status PriorValue="0">1</Marital_Status>
        </Personal>
        <Info>
            <CountryOfBirth PriorValue="IND">ESP</CountryOfBirth>
        </Info>
    </Emp>

谢谢你的帮助。

4

1 回答 1

2

利用

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

<xsl:template match="*[not(*) and not(@PriorValue)]"/>
于 2013-09-17T17:07:58.110 回答