繁体   English   中英

删除 xml 标记和与 xsl 文件关联的子项

[英]Remove xml tag and associated child with xsl file

我面临关于 liquibase 变更日志的问题。 我需要删除与特定子标签关联的特定标签。

下面关于Db-Changelog,需要自动删除子标签changeSet关联的标签alterSequence


<?xml version="1.1" encoding="UTF-8" standalone="no"?>

<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.6.xsd">
    <changeSet author="abc(generated)" id="1580482453362-1">
        <addColumn tableName="abc">
            <column defaultValueBoolean="true" name="abc" type="bool">
                <constraints nullable="false"/>
            </column>
        </addColumn>
    </changeSet>
    <changeSet author="abc (generated)" id="1591190895113-1">
        <alterSequence sequenceName="hibernate_sequence"/>
    </changeSet>
    <changeSet author="abc (generated)" id="v1.6.0">
        <tagDatabase tag="v1.6.0" />
    </changeSet>
</databaseChangeLog>

感谢 Maven 插件 xml-maven-plugin,借助 xsl 样式表,可以创建另一个变更日志。 但是现在,我做了一些尝试,但它不起作用。 (全部复制)


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

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


    <xsl:template match="databaseChangeLog[changeSet[alterSequence/@sequenceName='hibernate_sequence']]" />


</xsl:stylesheet>

有人看到这里有什么问题吗?

在此先感谢您的支持。

如果您的处理器支持 XSLT 2.0,那么您可以执行以下操作:

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xpath-default-namespace="http://www.liquibase.org/xml/ns/dbchangelog">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

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

<xsl:template match="changeSet[alterSequence/@sequenceName='hibernate_sequence']" />

</xsl:stylesheet>

请注意xsl:stylesheet元素上的xpath-default-namespace属性。 没有它,第二个模板将不匹配,因为源 XML 包含一个默认命名空间声明xmlns="http://www.liquibase.org/xml/ns/dbchangelog"将其所有元素放在一个命名空间中。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM