如何通过xsd从xml中删除空标记或空标记

时间:2015-04-10 14:50:04

标签: xml xsd

下面是我的xml;我通过xsd使用datastage ETL工具生成这个xml,现在我的要求是在下面的xml我没有note标记的数据,即使我在xml中得到note标记,我不想在我的XML;你能否建议我如何删除该标签

      <term
           rid="6662c0f2.e1b1ec6c.a1fk8pal9.8hqrjus.6af65b.8lr7d8vtg6ibohsre1bni"
           name="Test Term" longDescription="  " status="CANDIDATE"
           example="  " type="NONE" isModifier="false" workflowStatus="Published">
           <parentCategory identity="Test Category_Edit" rid="6662c0f2.ee6a64fe.a1fk62v4g.c0kd2bc.0rjqdm.feik8m3int29gfigeshsp"/>
           <replacedByTerm identity="Test Category_Edit::TestTerm 6" rid="6662c0f2.e1b1ec6c.a1fka7kac.1khu23o.2u72oe.bhpdj3dkdshb026mkdqks"/>
           <referencedByCategories>
                <categoryRef identity="Test RuleBook Category"
                     rid="6662c0f2.ee6a64fe.a1fkahnel.nso45vp.cns86c.758gjtic3rakunadr1v1k"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <categoryRef identity="Test ACE Category"
                     rid="6662c0f2.ee6a64fe.a1fkahnel.nso4pkh.3pmfh7.ccc8kcdsml2s8hdhtld7k"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </referencedByCategories>
           <assignedAssets>
                <BIReportMemberRef
                     reportModel="GAS Reporting - Detail"
                     reportModelNameSpace="sat1msmap054.nao.global.gmacfs.com\Public Folders\Auto Finance Packages\GAS Reporting - Detail\GAS Reporting - Detail\"
                     reportCollection="DIM_CONTRACT_ORA"
                     reportCollectionNameSpace="GAS Reporting - Detail/GAS - Database View"
                     reportMember="TERM"
                     nameSpace="[GAS - Database View].[DIM_CONTRACT_ORA]"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </assignedAssets>
           <customAttributes>
                <customAttributeValue
                     customAttribute="ERM - General Process Category"
                     value="Advertising and Marketing"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <customAttributeValue customAttribute="Changecode"
                     value="Y" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <customAttributeValue
                     customAttribute="Test Attribute 1" value="2"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <customAttributeValue
                     customAttribute="03. Is Reference Data?"
                     value="Yes" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <customAttributeValue
                     customAttribute="06. Data Quality Performed?"
                     value="No" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </customAttributes>
           <relatedTerms>
                <termRef identity="Test Category_Edit::Test Term5"
                     rid="6662c0f2.e1b1ec6c.a1fka7kac.1khv5h5.dmdrre.h0dusknvjnvdde1osbv1s"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <termRef identity="Test Category_Edit::TestTerm 7"
                     rid="6662c0f2.e1b1ec6c.a1fka7kac.1khuk2l.erslsg.shh1dj9auomm9p97vr5us"
                     xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </relatedTerms>
           <note/>
           <labels>
                <label name="DFS Rulebook" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <label name="FR Y-9C H1-B Retail" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
                <label name="DFS - Servicing" xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"/>
           </labels>
           <steward userName="M7HA75" type="USER"/>
      </term>

1 个答案:

答案 0 :(得分:0)

正如@potame所说的那样是XSL-T ..你可以使用以下XSL

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

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

    <xsl:template match="*[not(@*|*|comment()|processing-instruction()) and normalize-space()='']"/>
</xsl:stylesheet>

上面的XSL删除所有空标记。