数组的xslt concat值

时间:2018-06-25 09:54:05

标签: xslt saxon

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

<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。但是我不知道如何编写此选择,或者甚至不可能这样。

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

1 个答案:

答案 0 :(得分:0)

有很多方法可以做到这一点。这是一对...

<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]]"/>