2013-10-17 1 views
1

다음 문제를 해결하려면 XSL 1.0을 사용해야합니다. 나는 초보자 인 XSL이므로 사소한 일이라면 나와 함께 견뎌주십시오.XSL 1.0 난이도 문자열

transform.xsl이라는 파일을 사용하여 left.xml을 right.xml로 변환합니다. 나는 그 파일들을 보여줄 것이고 그 다음에 그 논리를 설명 할 것이다.

다음
<?xml version="1.0" ?> 
<parties> 
    <party> 
     <id>123</id> 
     <pending>456,789,234</pending> 
     <name>NYC Film Festival</name> 
    </party> 

    <party> 
     <id>345</id> 
     <pending>234</pending> 
     <name>Montreal Film Festival</name> 
    </party> 

    <party> 
     <id>345</id> 
     <pending /> 
     <name>LA Film Festival</name> 
    </party> 
</parties> 

다음과 같이

<?xml version="1.0" ?> 
    <parties> 
     <Aparty name="NYC Film Festival" id="456"/> 
     <Aparty name="NYC Film Festival" id="789"/> 
     <Aparty name="NYC Film Festival" id="234"/> 

     <Aparty name="Montreal Film Festival" id=234/> 

     <Aparty name="LA Film festival" id=345> 

    </parties> 

아이디어는 right.xml입니다 : 여기

는 left.xml입니다. left.xml을 고려하십시오. party 내의 보류중인 노드가 비어 있으면 right.xml에 id를 사용하십시오. 그렇지 않으면 보류중인 태그 안의 내용을 분할하고 각각에 대해 노드를 삽입하십시오. 내가 XSL 1.0을 사용해야하기 때문에 분할이 내게 던졌습니다.

누군가가 도와 줄 수 있습니까? 이

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

    <xsl:template match="/"> 
     <xsl:element name="parties"> 
      <xsl:apply-templates select="parties/party"/> 
     </xsl:element> 
    </xsl:template> 

    <xsl:template match="parties/party"> 
     <xsl:choose> 
      <xsl:when test="boolean(pending) and string(pending) != ''"> 
       <xsl:element name="Aparty"> 
        <xsl:attribute name="name"> 
         <xsl:value-of select="name"/> 
        </xsl:attribute> 
        <xsl:attribute name="id"> 
         <xsl:value-of select="pending"/> 
        </xsl:attribute> 
       </xsl:element> 
      </xsl:when> 
      <xsl:otherwise> 
       <xsl:element name="Aparty"> 
        <xsl:attribute name="name"> 
         <xsl:value-of select="name"/> 
        </xsl:attribute> 
        <xsl:attribute name="id"> 
         <xsl:value-of select="id"/> 
        </xsl:attribute> 
       </xsl:element> 
      </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

</xsl:stylesheet> 

답변

0

당신은 다른 템플릿에 반복적으로 값을 보류중인 목록을 처리 할 수처럼

나의 현재 transform.xsl 보인다. 첫 번째 보류중인 ID에 대해 Aparty을 생성 한 다음 처리 할 다음 반복을 위해 나머지 ID를 전달하는 것이 아이디어입니다.

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

    <xsl:template match="/"> 
    <xsl:element name="parties"> 
     <xsl:apply-templates select="parties/party"/> 
    </xsl:element> 
    </xsl:template> 

    <xsl:template match="parties/party"> 
    <xsl:choose> 
     <xsl:when test="boolean(pending) and string(pending) != ''"> 
     <xsl:call-template name="generateAparty"> 
      <xsl:with-param name="name" select="name"/> 
      <xsl:with-param name="ids" select="pending"/> 
     </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:element name="Aparty"> 
      <xsl:attribute name="name"> 
      <xsl:value-of select="name"/> 
      </xsl:attribute> 
      <xsl:attribute name="id"> 
      <xsl:value-of select="id"/> 
      </xsl:attribute> 
     </xsl:element> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

    <xsl:template name="generateAparty"> 
    <xsl:param name="name"/> 
    <xsl:param name="ids"/> 

    <xsl:choose> 
     <xsl:when test="contains($ids, ',') = false()"> 
     <!-- 1 id left --> 
     <xsl:element name="Aparty"> 
      <xsl:attribute name="name"> 
      <xsl:value-of select="$name"/> 
      </xsl:attribute> 
      <xsl:attribute name="id"> 
      <xsl:value-of select="$ids"/> 
      </xsl:attribute> 
     </xsl:element> 
     </xsl:when> 
     <xsl:otherwise> 
     <!-- Create element for 1st pending id in the list --> 
     <xsl:element name="Aparty"> 
      <xsl:attribute name="name"> 
      <xsl:value-of select="$name"/> 
      </xsl:attribute> 
      <xsl:attribute name="id"> 
      <xsl:value-of select="substring-before($ids, ',')"/> 
      </xsl:attribute> 
     </xsl:element> 
     <xsl:call-template name="generateAparty"> 
      <xsl:with-param name="name" select="$name"/> 
      <xsl:with-param name="ids" select="substring-after($ids, ',')"/> 
     </xsl:call-template> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 
</xsl:stylesheet> 
관련 문제