XML에 템플릿을 적용하기 전에 XSL 매개 변수에 템플릿을 적용 할 수 있습니까?

StackOverflow https://stackoverflow.com/questions/3287186

  •  17-09-2020
  •  | 
  •  

문제

문자열이되는 XSL 매개 변수가 있습니다.나는 그 문자열을 구문 분석하고, xsl에 템플릿을 적용하려는 각 하위 문자열 값에 대해 분할하고 싶습니다.

이하입니까?그렇다면 낙관적 인 해결책을 조언 해 주시겠습니까?

감사합니다

도움이 되었습니까?

해결책

편집 : 죄송합니다.

대답은 입니다.

입력 :

<secuence>Item1 Item2 Item3</secuence>
.

스타일 시트 :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="secuence/text()" name="secuence">
        <xsl:param name="string" select="."/>
        <xsl:param name="separator" select="' '"/>
        <xsl:if test="$string != ''">
            <xsl:choose>
                <xsl:when test="contains($string,$separator)">
                    <xsl:call-template name="secuence">
                        <xsl:with-param name="string" select="substring-before($string,$separator)"/>
                        <xsl:with-param name="separator" select="$separator"/>
                    </xsl:call-template>
                    <xsl:call-template name="secuence">
                        <xsl:with-param name="string" select="substring-after($string,$separator)"/>
                        <xsl:with-param name="separator" select="$separator"/>
                    </xsl:call-template>
                </xsl:when>
                <xsl:otherwise>
                    <!-- Your desired template -->
                    <Item>
                        <xsl:value-of select="$string"/>
                    </Item>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
.

결과 :

<secuence>
    <Item>Item1</Item>
    <Item>Item2</Item>
    <Item>Item3</Item>
</secuence>
.

다른 팁

무슨 뜻인지 확신하지만이 패턴을 복사하는 것이 도움이 될 수 있습니다 : XSLT - 쉼표로 분리하고 렌더링하는 가장 좋은 방법 HTML로 텍스트 분리

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top