数组的 xslt concat 值

xslt concat value of array

我想应用其中指定元素包含以某个常量为前缀的数组值的模板。

<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 的所有节点,其中属性 sequenceNameSEQ_+value of some coreTables。但我不知道如何写这个 select 或者是否可以这样写。

我正在使用 xslt 2 和 saxon 9.8he。

您可以通过多种方式执行此操作。这是一对...

<xsl:apply-templates 
     select="changeSet[createSequence/@sequenceName = (for $i in $coreTables return concat('SEQ_', $i))]"/>

<xsl:apply-templates 
     select="changeSet[createSequence[starts-with(@sequenceName, 'SEQ_') and substring-after(@sequenceName, 'SEQ_') = $coreTables]]"/>