【发布时间】:2018-06-25 09:54:05
【问题描述】:
我想应用模板,其中指定元素包含以某个常量为前缀的数组值。
<xsl:variable name="coreTables"
select="('TAB1', 'TAB2')" />
<xsl:template match="node()[not(self::*)]">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="*">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="node()|@*"/>
</xsl:element>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
<xsl:template match="databaseChangeLog">
<xsl:comment> CORE TABLES </xsl:comment>
<xsl:apply-templates select="changeSet[createTable/@tableName=$coreTables]"/>
<xsl:comment> CORE SEQUENCES </xsl:comment>
<xsl:apply-templates select="changeSet[createSequence/@sequenceName='SEQ_'[$coreTables]]"/>
</xsl:template>
这是示例 xml:
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
<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-3.6.xsd
http://www.liquibase.org/xml/ns/dbchangelog">
<changeSet id="1" author="a">
<createTable tableName="TAB1">
<column></column>
</createTable>
</changeSet>
<changeSet id="1-1" author="a">
<createSequence sequenceName="SEQ_TAB1" />
</changeSet>
<changeSet id="4" author="A">
<createTable tableName="TAB4">
<column></column>
</createTable>
</changeSet>
</databaseChangeLog>
所以最后一个apply-templates 我想匹配createSequence 的所有节点,其中属性sequenceName 是SEQ_+value of some coreTables。但我不知道如何编写这个选择,或者是否有可能这样。
我正在使用 xslt 2 和 saxon 9.8he。
【问题讨论】:
-
是的,有可能。但是您可以编辑您的问题以显示输入 XML 的示例吗?谢谢!
-
抱歉忘记了。 ...添加示例