How to find last to preview work and store to my field in xslt?

后端 未结 1 1879
生来不讨喜
生来不讨喜 2021-01-24 05:44

HI How to find last to preview word in xslt i have search to google but not found correct solution can u please help me

MY code is

i have this code as like thi

相关标签:
1条回答
  • 2021-01-24 06:15

    To do this in pure XSLT 1.0, with no extensions, use:

    <xsl:template name="token-before-last">
        <xsl:param name="text"/>
        <xsl:param name="delimiter" select="'/'"/>
        <xsl:variable name="next-text" select="substring-after($text, $delimiter)" />
        <xsl:choose>
            <xsl:when test="contains($next-text, $delimiter)">
                <!-- recursive call -->
                <xsl:call-template name="token-before-last">
                    <xsl:with-param name="text" select="$next-text"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="substring-before($text, $delimiter)"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    

    Example of call:

    <xsl:template match="tag">
        <result>
            <xsl:call-template name="token-before-last">
                <xsl:with-param name="text" select="."/>
            </xsl:call-template>
        </result>
    </xsl:template>
    

    Demo: http://xsltransform.net/94AbWAB


    If your processor supports the EXSLT str:tokenize() extension function, you can do simply:

    <xsl:template match="tag">
        <result>
            <xsl:value-of select="str:tokenize(., '/')[last() -1]"/>
        </result>
    </xsl:template>
    

    Demo: http://xsltransform.net/94AbWAB/1

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