我有一個XSLT需要一個。 delimted字符串,將其分解成兩個字段一個SQL語句:更有效的XSLT方法 - 每個
<xsl:for-each select="tokenize(Path,'\.')">
<xsl:choose>
<xsl:when test="position() = 1 and position() = last()">SITE = '<xsl:value-of select="."/>' AND PATH = ''</xsl:when>
<xsl:when test="position() = 1 and position() != last()">SITE = '<xsl:value-of select="."/>' </xsl:when>
<xsl:when test="position() = 2 and position() = last()">AND PATH = '<xsl:value-of select="."/>' </xsl:when>
<xsl:when test="position() = 2">AND PATH = '<xsl:value-of select="."/></xsl:when>
<xsl:when test="position() > 2 and position() != last()">.<xsl:value-of select="."/></xsl:when>
<xsl:when test="position() > 2 and position() = last()">.<xsl:value-of select="."/>' </xsl:when>
<xsl:otherwise>zxyarglfaux</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
結果如下:
INPUT: North OUTPUT: SITE = 'North' AND PATH = ''
INPUT: North.A OUTPUT: SITE = 'North' AND PATH = 'A'
INPUT: North.A.B OUTPUT: SITE = 'North' AND PATH = 'A.B'
INPUT: North.A.B.C OUTPUT: SITE = 'North' AND PATH = 'A.B.C'
這工作,但很長時間。任何人都可以看到更有效的方法嗎?
謝謝!
你可能有興趣在一個優越的解決方案。看到我的答案。 –