XSLT - 将单个属性分离为具有属性的多个元素

问题描述 投票:0回答:1
xml xslt xslt-2.0
1个回答
0
投票

我想我通过使用得到了预期的结果:

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

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

<xsl:template match="xref[contains(@rid, ' ')]">
    <xsl:variable name="ref" select="text()"/>
    <xsl:for-each select="tokenize(@rid, ' ')">
        <xsl:choose>
            <xsl:when test="position()=1">
                <xref ref-type="bibr" rid="{.}">
                    <xsl:value-of select="substring-before($ref, '&#x2013;')"/>
                </xref>
            </xsl:when>
            <xsl:when test="position()=last()">
                <xsl:text>&#x2013;</xsl:text>
                <xref ref-type="bibr" rid="{.}">
                    <xsl:value-of select="substring-after($ref, '&#x2013;')"/>
                </xref>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text> </xsl:text>
                <xref ref-type="bibr" rid="{.}"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

但这主要是基于根据您的单个示例猜测规则是什么......

© www.soinside.com 2019 - 2024. All rights reserved.