2017-01-16 1 views
0

죄송합니다.SSLS의 XLST를 통해 자식 노드 추가

내가 우리 트레이너의 Captivate를 퀴즈에서이 같은 XML 파일이 있습니다 요소에 속성을 변환하는 내가 (여기에 지역 사회의 도움으로) XLST를 통해 관리 한

를, 무엇을 내가 옆에 무엇을 하시겠습니까 위의 <CompanyName>에서 위의 <TotalQuestions>으로 요소를 가져 와서 새 노드에 넣습니다. <userdata>. 이것은 내가 원하는 것입니다

<Course> 
    <CompanyName value='Hanover'/> 
    <DepartmentName value='ICT'/> 
    <CourseName value='TEST'/> 
    <LearnerName value='Paul Wilson'/> 
    <LearnerID value='05757'/> 
    <LessonName value='ICT Literacy Test'></LessonName> 
    <QuizAttempts value='1'></QuizAttempts> 
    <TotalQuestions value='26'></TotalQuestions> 
    <Result><CoreData><Status value='completed'></Status> 
    <Location value='30'></Location> 
    <RawScore value='100'></RawScore> 
    <MaxScore value='100'></MaxScore> 
    <MinScore value='0'></MinScore> 
    <SessionTime value='undefined'></SessionTime> 
    </CoreData> 
    <InteractionData><Interactions><Date value='2016/11/23'></Date> 
    <InteractionTime value='11/23/2016T8:40:32'></InteractionTime> 
    <InteractionID value='WN_Open_File'></InteractionID> 
    <ObjectiveID value='Quiz_201611414227'></ObjectiveID> 
    <InteractionType value='choice'></InteractionType> 
    <CorrectResponse value='1'></CorrectResponse> 
    <StudentResponse value='1'></StudentResponse> 
    <Result value='C'></Result> 
    <Weight value='1'></Weight> 
    <Latency value='1916'></Latency> 
    <Attempt value='1'></Attempt> 
    </Interactions> 
    <Interactions><Date value='2016/11/23'></Date> 
    <InteractionTime value='11/23/2016T8:40:43'></InteractionTime> 
    <InteractionID value='WN_Close_Window'></InteractionID> 
    <ObjectiveID value='Quiz_201611414227'></ObjectiveID> 
    <InteractionType value='choice'></InteractionType> 
    <CorrectResponse value='1'></CorrectResponse> 
    <StudentResponse value='1'></StudentResponse> 
    <Result value='C'></Result> 
    <Weight value='1'></Weight> 
    <Latency value='10889'></Latency> 
    <Attempt value='1'></Attempt> 
    </Interactions> 
    <Interactions><Date value='2016/11/23'></Date> 
    <InteractionTime value='11/23/2016T8:44:41'></InteractionTime> 
    <InteractionID value='MO_Address'></InteractionID> 
    <ObjectiveID value='Quiz_2016103113211'></ObjectiveID> 
    <InteractionType value='choice'></InteractionType> 
    <CorrectResponse value='B'></CorrectResponse> 
    <StudentResponse value='B'></StudentResponse> 
    <Result value='C'></Result> 
    <Weight value='1'></Weight> 
    <Latency value='6601'></Latency> 
    <Attempt value='1'></Attempt> 
    </Interactions> 
    </InteractionData> 
    </Result> 
    </Course> 

:

내가 가진 무엇 나는 다음 XSLT 코드를 사용하려고했습니다

<?xml version="1.0" encoding="utf-8"?> 
<Course> 
    <UserData> 
    <CompanyName>Hanover</CompanyName> 
    <DepartmentName>ICT</DepartmentName> 
    <CourseName>TEST</CourseName> 
    <LearnerName>Paul Wilson</LearnerName> 
    <LearnerID>05757</LearnerID> 
    <LessonName>ICT Literacy Test</LessonName> 
    <QuizAttempts>1</QuizAttempts> 
    <TotalQuestions>26</TotalQuestions> 
    </UserData> 
    <Result> 
     <CoreData> 
     <Status>completed</Status> 
     <Location>30</Location> 
     <RawScore>100</RawScore> 
     <MaxScore>100</MaxScore> 
     <MinScore>0</MinScore> 
     <SessionTime>undefined</SessionTime> 
     </CoreData> 
     <InteractionData> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:40:32</InteractionTime> 
      <InteractionID>WN_Open_File</InteractionID> 
      <ObjectiveID>Quiz_201611414227</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>1</CorrectResponse> 
      <StudentResponse>1</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>1916</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:40:43</InteractionTime> 
      <InteractionID>WN_Close_Window</InteractionID> 
      <ObjectiveID>Quiz_201611414227</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>1</CorrectResponse> 
      <StudentResponse>1</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>10889</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:44:41</InteractionTime> 
      <InteractionID>MO_Address</InteractionID> 
      <ObjectiveID>Quiz_2016103113211</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>B</CorrectResponse> 
      <StudentResponse>B</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>6601</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     </InteractionData> 
    </Result> 

</Course> 

:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" 
> 
    <xsl:output method="xml" indent="yes"/> 

    <xsl:template match="Course"> 
     <xsl:copy> 
      <UserData> 
       <xsl:apply-templates select="@*|node()"/> 
      </UserData> 
     </xsl:copy> 
    </xsl:template> 


    <xsl:template match="@* | node()"> 
     <xsl:copy> 
      <xsl:apply-templates select="@* | node()"/> 
     </xsl:copy> 
    </xsl:template> 


    <xsl:template match="*[@value]"> 
     <xsl:copy> 
      <xsl:value-of select="@value"/> 
     </xsl:copy> 
    </xsl:template> 



</xsl:stylesheet> 

을하지만, 나에게 이것을 준다 :

<?xml version="1.0" encoding="utf-8"?> 
<Course> 
    <UserData> 
    <CompanyName>Hanover</CompanyName> 
    <DepartmentName>ICT</DepartmentName> 
    <CourseName>TEST</CourseName> 
    <LearnerName>Paul Wilson</LearnerName> 
    <LearnerID>05757</LearnerID> 
    <LessonName>ICT Literacy Test</LessonName> 
    <QuizAttempts>1</QuizAttempts> 
    <TotalQuestions>26</TotalQuestions> 
    <Result> 
     <CoreData> 
     <Status>completed</Status> 
     <Location>30</Location> 
     <RawScore>100</RawScore> 
     <MaxScore>100</MaxScore> 
     <MinScore>0</MinScore> 
     <SessionTime>undefined</SessionTime> 
     </CoreData> 
     <InteractionData> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:40:32</InteractionTime> 
      <InteractionID>WN_Open_File</InteractionID> 
      <ObjectiveID>Quiz_201611414227</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>1</CorrectResponse> 
      <StudentResponse>1</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>1916</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:40:43</InteractionTime> 
      <InteractionID>WN_Close_Window</InteractionID> 
      <ObjectiveID>Quiz_201611414227</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>1</CorrectResponse> 
      <StudentResponse>1</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>10889</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     <Interactions> 
      <Date>2016/11/23</Date> 
      <InteractionTime>11/23/2016T8:44:41</InteractionTime> 
      <InteractionID>MO_Address</InteractionID> 
      <ObjectiveID>Quiz_2016103113211</ObjectiveID> 
      <InteractionType>choice</InteractionType> 
      <CorrectResponse>B</CorrectResponse> 
      <StudentResponse>B</StudentResponse> 
      <Result>C</Result> 
      <Weight>1</Weight> 
      <Latency>6601</Latency> 
      <Attempt>1</Attempt> 
     </Interactions> 
     </InteractionData> 
    </Result> 
    </UserData> 
</Course> 

내가 뭘 잘못하고 있는지 알기나 해?

+0

질문을 편집하고 예상 된 결과를 추가하십시오. 이 예제를 최소화하는 것이 유용 할 것입니다. [mcve]. –

+0

나는 그것을 시도 할 것이다. 전에 캐릭터 제한을 치고있었습니다. –

답변

0

AFAICT, 당신은하고 싶지 :

XSLT 1.0

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

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Course"> 
    <xsl:copy> 
     <UserData> 
      <xsl:apply-templates select="*[not(self::Result)]"/> 
     </UserData> 
     <xsl:apply-templates select="Result"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="*[@value]"> 
    <xsl:copy> 
     <xsl:value-of select="@value"/> 
    </xsl:copy> 
</xsl:template> 

</xsl:stylesheet> 
+0

를 주석 처리했으면 SSIS에서 작동했습니다. 정말 고마워요. –