2013-04-02 4 views
0

을 사용하여 요소를 분할하는 방법; delimiter.my 요구 사항은 아래와 같습니다.스플릿 속성 사용; XSLT에서 구분 기호로 사용

입력 :

<Element1>C:KEK39519US; U:085896395195; A:K39519US; B:S2345843</Element1> 

출력 : 입력이 C:KEK39519US; U:085896395195; B:S2345843 처럼 언젠가이 U:085896395195; A:K39519US; 언젠가 추천하기 추천이 C:KEK39519US; A:K39519US; B:S2345843 같은 시간이 온다 시간을 same.some하지 때마다이

<CustItem>KEK39519US</CustItem> 

<UNumber>085896395195</UNumber> 

<ANumber>K39519US</ANumber> 

<BNumber>S2345843</BNumber> 

C:KEK39519US; U:085896395195; A:K39519US;

+0

XSLT 1.0 또는 2.0을 사용하고 있습니까? –

+0

XSLT 1.0을 사용하고 있습니다. – sum

답변

2

XSLT 1.0에서이를 해결하려면 재귀 적으로 자체를 호출하는 명명 된 템플릿이 필요할 수 있습니다. 템플릿은 첫 번째 세미콜론 앞에있는 문자열을 처리하고 이에 따라 요소를 출력합니다. (있는 경우) 그런 다음 재귀 여기

는 XML에 적용되는 전체 XSLT

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

    <xsl:template match="Element1"> 
     <xsl:call-template name="outputElements"> 
     <xsl:with-param name="list" select="." /> 
     </xsl:call-template> 
    </xsl:template> 

    <xsl:template name="outputElements"> 
     <xsl:param name="list"/> 

     <xsl:variable name="first" select="normalize-space(substring-before(concat($list, ';'), ';'))"/> 
     <xsl:variable name="remaining" select="normalize-space(substring-after($list, ';'))"/> 

     <xsl:call-template name="createElement"> 
     <xsl:with-param name="element" select="$first" /> 
     </xsl:call-template> 

     <!-- If there are still elements left in the list, call the template recursively --> 
     <xsl:if test="$remaining"> 
     <xsl:call-template name="outputElements"> 
      <xsl:with-param name="list" select="$remaining"/> 
     </xsl:call-template> 
     </xsl:if> 
    </xsl:template> 

    <xsl:template name="createElement"> 
     <xsl:param name="element"/> 
     <xsl:variable name="elementName"> 
     <xsl:choose> 
      <xsl:when test="substring-before($element, ':') = 'C'">CustItem</xsl:when> 
      <xsl:otherwise><xsl:value-of select="concat(substring-before($element, ':'), 'Number')" /></xsl:otherwise> 
     </xsl:choose> 
     </xsl:variable> 
     <xsl:element name="{$elementName}"> 
     <xsl:value-of select="substring-after($element, ':')" /> 
     </xsl:element> 
    </xsl:template> 
</xsl:stylesheet> 

인이 세미콜론 후 문자열의 나머지 부분과 함께 자신을 호출, 다음 출력은

<CustItem>KEK39519US</CustItem> 
<UNumber>085896395195</UNumber> 
<ANumber>K39519US</ANumber> 
<BNumber>S2345843</BNumber> 

각 새 요소의 이름을 지정하는 데 특성 값 템플릿을 사용합니다.

관련 문제