How to iterate over IDREFS values in XSLT 1.0?

后端 未结 1 1660
迷失自我
迷失自我 2020-12-07 04:12

I have an xml that uses an IDREFS field. I need to extract those id to put their in their own element.

Here\'s the basic structure I think I need but I don\'t know w

相关标签:
1条回答
  • 2020-12-07 04:41

    You need to tokenize the value of the idrefsField attribute. XSLT 1.0 has no native tokenize() function, so you need to call a recursive named template to do this for you:

    <xsl:template match="node_With_IDREFS_field">
        <xsl:copy>
            <xsl:call-template name="tokenize">
                <xsl:with-param name="text" select="@idrefsField"/>
            </xsl:call-template>
        </xsl:copy>
    </xsl:template>
    
    <xsl:template name="tokenize">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="' '"/>
        <xsl:variable name="token" select="substring-before(concat($text, $delimiter), $delimiter)" />
            <xsl:if test="$token">
                <newElement ref="{$token}"/>
            </xsl:if>
            <xsl:if test="contains($text, $delimiter)">
                <!-- recursive call -->
                <xsl:call-template name="tokenize">
                    <xsl:with-param name="text" select="substring-after($text, $delimiter)"/>
                </xsl:call-template>
            </xsl:if>
    </xsl:template>
    

    Alternatively, if your processor supports it, you could use the EXSLT str:tokenize() extension function.

    0 讨论(0)
提交回复
热议问题