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> 

これは私が欲しいものです:

<?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> 

しかし:私は、次の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"?> 
<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で動作しました。 ありがとうございます。 –

関連する問題