我有一個這樣的XSLT施加:XSLT變化/上覆蓋屬性複製的不(使用撒克遜)
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:db="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="db:databaseChangeLog/db:changeSet">
<xsl:if test="name(*[1])='createTable'">
<xsl:result-document href="base/tables/{position()}_{name(*[1])}_{*[1]/@tableName}.xml">
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<xsl:copy-of select="."/>
<xsl:copy-of select="../db:changeSet[name(*[1])='createIndex' and *[1]/@tableName= current()/*[1]/@tableName ]" />
</databaseChangeLog>
</xsl:result-document>
</xsl:if>
</xsl:for-each>
</xsl:template>
<xsl:template match="@* | node()" mode="copy">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="db:changeSet/@author" mode="copy">
<xsl:attribute name="author">
<xsl:value-of select="'sakhunzai'"/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet>
XML部分文件
<changeSet author="xxx (generated)" id="1358259674512-26">
<createIndex indexName="category_id" tableName="teams" unique="false">
<column name="audience_id"/>
</createIndex>
</changeSet>
<changeSet author="xxx (generated)" id="1358259674512-29">
<createIndex indexName="id" tableName="users" unique="false">
<column name="id"/>
<column name="career_lead_id"/>
</createIndex>
</changeSet>
我要重寫的屬性值changeSet(作者和ID)。請幫我修復xslt。
一切工作正常,但@author atrribute值不會在目標XML文件更改 注:由於在xsltproc做不到的事情,我切換到撒克遜基於java的處理器如
java -jar /usr/local/liquibase/saxon/saxon9he.jar common.xml table.xslt
工作XSLT
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet xmlns:db="http://www.liquibase.org/xml/ns/dbchangelog" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/">
<xsl:for-each select="db:databaseChangeLog/db:changeSet[db:createTable]">
<xsl:result-document href="base/tables/{position()}_{name(*[1])}_{*[1]/@tableName}.xml">
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-2.0.xsd">
<xsl:apply-templates select="." mode="copy"/>
<xsl:apply-templates select="../db:changeSet[db:createIndex and *[1]/@tableName= current()/*[1]/@tableName ]" mode="copy"/>
</databaseChangeLog>
</xsl:result-document>
</xsl:for-each>
</xsl:template>
<xsl:template match="node()" mode="copy">
<xsl:copy>
<xsl:attribute name="author">sakhunzai</xsl:attribute>
<xsl:copy-of select="@id|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
請問您是否可以在答案的最後加上修改後的完整xslt。我只是混淆了修改的位置 – sakhunzai
添加了完整的XSLT。 – JLRishe
我按照你的建議修復了xslt,但是@mode沒有與撒克遜工作(對不起,我切換到撒克遜)請檢查我的編輯 – sakhunzai