Home > Software engineering >  xslt 3.0 mapping and validation
xslt 3.0 mapping and validation

Time:11-08

I have an Input file and Source file of courses in a combined xml. I m using xslt3.0 I need to validate Instructor id ,Location/Room with the given source xml Source xml

<?xml version='1.0' encoding='utf-8'?>
<FileAndCourses>
    <Maps>
        <Locations>
            <Location>
                <InternalValue>7070</InternalValue>
                <ExternalValue>Laval</ExternalValue>
            </Location>
                    </Locations>
            <Rooms>
                <Room>
                    <InternalValue>LOCATION-6-3881</InternalValue>
                    <ExternalValue>Ottawa District Training Center</ExternalValue>
                </Room>
            </Rooms>  
            
    </Maps>
    <Instructors>
        <Instructor>
        <InstructorID>119417764</InstructorID>
        <WorkdayUserName>AXH4006</WorkdayUserName>
    </Instructor>
        <Instructor>
            <InstructorID>713400041</InstructorID>
            <WorkdayUserName>TXB786</WorkdayUserName>
        </Instructor>
        <Instructor>
            <InstructorID>713500126</InstructorID>
            <WorkdayUserName>LXF99S</WorkdayUserName>
        </Instructor>
    </Instructors>
      <AllCourses
        xmlns:xsd="http://www.w3.org/2001/XMLSchema"
        xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
        xmlns:wd="urn:com.workday/bsvc">
                <wd:Learning_Course>
            <wd:Learning_Blended_Course_Reference>
                <wd:ID wd:type="WID">88388986cbbf10128d2b24f4f5c40000</wd:ID>
                <wd:ID wd:type="Learning_Course_ID">00151744</wd:ID>
                <wd:ID wd:type="Learning_Course">Designing Kitchens Part II</wd:ID>
            </wd:Learning_Blended_Course_Reference>
            <wd:Learning_Course_Data>
                <wd:ID>00151744</wd:ID>
                <wd:Effective_Date>2014-10-04</wd:Effective_Date>
                <wd:Inactive>0</wd:Inactive>
                <wd:Course_Title>Designing Kitchens Part II</wd:Course_Title>
                <wd:Description>Designing Kitchens Part II</wd:Description>
                <wd:Course_Number>00151744</wd:Course_Number>
                <wd:Topic_Reference>
                    <wd:ID wd:type="WID">9d1f49654c8310154e239c7090fc0000</wd:ID>
                    <wd:ID wd:type="Learning_Topic">Product Knowledge - US</wd:ID>
                </wd:Topic_Reference>
                <wd:Language_Reference>
                    <wd:ID wd:type="WID">da594226446c11de98360015c5e6daf6</wd:ID>
                    <wd:ID wd:type="User_Language_ID">en_US</wd:ID>
                </wd:Language_Reference>
                <wd:Minimum_Enrollment_Capacity>0</wd:Minimum_Enrollment_Capacity>
                <wd:Maximum_Enrollment_Capacity>0</wd:Maximum_Enrollment_Capacity>
                <wd:Waitlist_Capacity>0</wd:Waitlist_Capacity>
                <wd:Unlimited_Capacity>1</wd:Unlimited_Capacity>
                <wd:Learning_Pricing_Data>
                    <wd:Pricing_Enabled>0</wd:Pricing_Enabled>
                    <wd:Price_in_Training_Credits>0</wd:Price_in_Training_Credits>
                </wd:Learning_Pricing_Data>
                <wd:Time_Value_Reference>
                    <wd:ID wd:type="WID">f31be4fd5caa10001d7c625e27014929</wd:ID>
                    <wd:ID wd:type="Learning_Time_Unit_ID">HOURS</wd:ID>
                </wd:Time_Value_Reference>
                <wd:Total_Course_Duration>18</wd:Total_Course_Duration>
                <wd:Enable_Auto_Enrollment_from_Waitlist>0</wd:Enable_Auto_Enrollment_from_Waitlist>
                <wd:Legacy_Course>1</wd:Legacy_Course>
                <wd:Allowed_Instructor_Reference>
                    <wd:ID wd:type="WID">88388986cbbf10124df56ab318140000</wd:ID>
                    <wd:ID wd:type="Learning_Instructor_ID">100735117</wd:ID>
                </wd:Allowed_Instructor_Reference>
                <wd:Allowed_Instructor_Reference>
                    <wd:ID wd:type="WID">b7f5fd27bc071018bbed7a460ce30000</wd:ID>
                    <wd:ID wd:type="Learning_Instructor_ID">119417764</wd:ID>
                </wd:Allowed_Instructor_Reference>
                <wd:Allowed_Instructor_Reference>
                    <wd:ID wd:type="WID">88388986cbbf10124df57b8e81f30002</wd:ID>
                    <wd:ID wd:type="Learning_Instructor_ID">104034590</wd:ID>
                </wd:Allowed_Instructor_Reference>
                <wd:All_Locations>0</wd:All_Locations>
                <wd:Exclude_from_Recommendations>1</wd:Exclude_from_Recommendations>
                <wd:Exclude_from_Search_and_Browse>0</wd:Exclude_from_Search_and_Browse>
                <wd:Disable_Express_Interest>1</wd:Disable_Express_Interest>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>1</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 1</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>2</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 2</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>3</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 3</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>4</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 4</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>5</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 5</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>6</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Instructor_Led_Webinar_Lesson_Data>
                        <wd:Title>Launch Class Link - HDU_VILT01 - 6</wd:Title>
                        <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                        <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                    </wd:Instructor_Led_Webinar_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>7</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                    <wd:Media_Lesson_Data>
                        <wd:Media_Reference>
                            <wd:ID wd:type="WID">88388986cbbf10128d2b23247d3f0004</wd:ID>
                            <wd:ID wd:type="Media_ID">MEDIA-6-4195</wd:ID>
                            <wd:ID wd:type="Workdrive_Item_ID">MEDIA-6-4195</wd:ID>
                        </wd:Media_Reference>
                        <wd:Learning_Course_Lesson_Title>Welcome to HDU Distance Learning</wd:Learning_Course_Lesson_Title>
                        <wd:Provide_Course_Grade>0</wd:Provide_Course_Grade>
                    </wd:Media_Lesson_Data>
                </wd:Course_Lesson_Data>
                <wd:Course_Lesson_Data>
                    <wd:Lesson_Order>8</wd:Lesson_Order>
                    <wd:Make_Lesson_Mandatory>0</wd:Make_Lesson_Mandatory>
                    <wd:Media_Lesson_Data>
                        <wd:Media_Reference>
                            <wd:ID wd:type="WID">358e28e73d5d10109aef5b042fc20000</wd:ID>
                            <wd:ID wd:type="Media_ID">cninv000000000020562.zip</wd:ID>
                            <wd:ID wd:type="Workdrive_Item_ID">cninv000000000020562.zip</wd:ID>
                        </wd:Media_Reference>
                        <wd:Learning_Course_Lesson_Title>Course Feedback HDUv3</wd:Learning_Course_Lesson_Title>
                        <wd:Provide_Course_Grade>0</wd:Provide_Course_Grade>
                    </wd:Media_Lesson_Data>
                </wd:Course_Lesson_Data>
            </wd:Learning_Course_Data>
        </wd:Learning_Course>
          <wd:Learning_Course>
              <wd:Learning_Blended_Course_Reference>
                  <wd:ID wd:type="WID">88388986cbbf10128d2c78dc802e0001</wd:ID>
                  <wd:ID wd:type="Learning_Course_ID">00170024CA</wd:ID>
                  <wd:ID wd:type="Learning_Course">Design Basics (Designer Training 4) - Virtual ILT</wd:ID>
              </wd:Learning_Blended_Course_Reference>
              <wd:Learning_Course_Data>
                  <wd:ID>00170024CA</wd:ID>
                  <wd:Effective_Date>2019-02-26</wd:Effective_Date>
                  <wd:Inactive>0</wd:Inactive>
                  <wd:Course_Title>Design Basics (Designer Training 4) - Virtual ILT</wd:Course_Title>
                  <wd:Description>&lt;p>In this 5 module virtual course the designer will learn the basics of drafting and laying out basic designs for Contractors and DIY customers.&lt;/p></wd:Description>
                  <wd:Course_Number>00170024CA</wd:Course_Number>
                  <wd:Topic_Reference>
                      <wd:ID wd:type="WID">9d1f49654c8310154e4430e071ef0000</wd:ID>
                      <wd:ID wd:type="Learning_Topic">Customer Service and Selling Skills - CAN</wd:ID>
                  </wd:Topic_Reference>
                  <wd:Language_Reference>
                      <wd:ID wd:type="WID">da5948c0446c11de98360015c5e6daf6</wd:ID>
                      <wd:ID wd:type="User_Language_ID">en_CA</wd:ID>
                  </wd:Language_Reference>
                  <wd:Minimum_Enrollment_Capacity>4</wd:Minimum_Enrollment_Capacity>
                  <wd:Maximum_Enrollment_Capacity>10</wd:Maximum_Enrollment_Capacity>
                  <wd:Waitlist_Capacity>0</wd:Waitlist_Capacity>
                  <wd:Unlimited_Capacity>0</wd:Unlimited_Capacity>
                  <wd:Learning_Pricing_Data>
                      <wd:Pricing_Enabled>0</wd:Pricing_Enabled>
                      <wd:Price_in_Training_Credits>0</wd:Price_in_Training_Credits>
                  </wd:Learning_Pricing_Data>
                  <wd:Time_Value_Reference>
                      <wd:ID wd:type="WID">f31be4fd5caa10001d7c6231be3b4927</wd:ID>
                      <wd:ID wd:type="Learning_Time_Unit_ID">MINUTES</wd:ID>
                  </wd:Time_Value_Reference>
                  <wd:Total_Course_Duration>900</wd:Total_Course_Duration>
                  <wd:Enable_Auto_Enrollment_from_Waitlist>0</wd:Enable_Auto_Enrollment_from_Waitlist>
                  <wd:Legacy_Course>1</wd:Legacy_Course>
                  <wd:Allowed_Instructor_Reference>
                      <wd:ID wd:type="WID">88388986cbbf10124df5cfa198ca0000</wd:ID>
                      <wd:ID wd:type="Learning_Instructor_ID">718700459</wd:ID>
                  </wd:Allowed_Instructor_Reference>
                  <wd:Allowed_Instructor_Reference>
                      <wd:ID wd:type="WID">88388986cbbf10124df5c99611170000</wd:ID>
                      <wd:ID wd:type="Learning_Instructor_ID">713400041</wd:ID>
                  </wd:Allowed_Instructor_Reference>
                  <wd:Allowed_Instructor_Reference>
                      <wd:ID wd:type="WID">88388986cbbf10124df5c72adbc60000</wd:ID>
                      <wd:ID wd:type="Learning_Instructor_ID">702300581</wd:ID>
                  </wd:Allowed_Instructor_Reference>
                  <wd:All_Locations>0</wd:All_Locations>
                  <wd:Exclude_from_Recommendations>1</wd:Exclude_from_Recommendations>
                  <wd:Exclude_from_Search_and_Browse>0</wd:Exclude_from_Search_and_Browse>
                  <wd:Disable_Express_Interest>1</wd:Disable_Express_Interest>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>1</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Instructor_Led_Webinar_Lesson_Data>
                          <wd:Title>Session 1</wd:Title>
                          <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                          <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                      </wd:Instructor_Led_Webinar_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>2</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Instructor_Led_Webinar_Lesson_Data>
                          <wd:Title>Session 2</wd:Title>
                          <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                          <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                      </wd:Instructor_Led_Webinar_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>3</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Instructor_Led_Webinar_Lesson_Data>
                          <wd:Title>Session 3</wd:Title>
                          <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                          <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                      </wd:Instructor_Led_Webinar_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>4</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Instructor_Led_Webinar_Lesson_Data>
                          <wd:Title>Session 4</wd:Title>
                          <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                          <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                      </wd:Instructor_Led_Webinar_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>5</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Instructor_Led_Webinar_Lesson_Data>
                          <wd:Title>Session 5</wd:Title>
                          <wd:Webinar_Lesson_Unit_Track_Attendance>1</wd:Webinar_Lesson_Unit_Track_Attendance>
                          <wd:Webinar_Lesson_Unit_Track_Grades>0</wd:Webinar_Lesson_Unit_Track_Grades>
                      </wd:Instructor_Led_Webinar_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>6</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>1</wd:Make_Lesson_Mandatory>
                      <wd:Media_Lesson_Data>
                          <wd:Media_Reference>
                              <wd:ID wd:type="WID">88388986cbbf10128d2c770c4c2b0003</wd:ID>
                              <wd:ID wd:type="Media_ID">MEDIA-6-4222</wd:ID>
                              <wd:ID wd:type="Workdrive_Item_ID">MEDIA-6-4222</wd:ID>
                          </wd:Media_Reference>
                          <wd:Learning_Course_Lesson_Title>Log in Instructions (Adobe Connect - Designer 4_DesignBasics) (updated May 2022)</wd:Learning_Course_Lesson_Title>
                          <wd:Provide_Course_Grade>0</wd:Provide_Course_Grade>
                      </wd:Media_Lesson_Data>
                  </wd:Course_Lesson_Data>
                  <wd:Course_Lesson_Data>
                      <wd:Lesson_Order>7</wd:Lesson_Order>
                      <wd:Make_Lesson_Mandatory>0</wd:Make_Lesson_Mandatory>
                      <wd:Media_Lesson_Data>
                          <wd:Media_Reference>
                              <wd:ID wd:type="WID">358e28e73d5d1010910342e9c79a0000</wd:ID>
                              <wd:ID wd:type="Media_ID">cninv000000000019226.zip</wd:ID>
                              <wd:ID wd:type="Workdrive_Item_ID">cninv000000000019226.zip</wd:ID>
                          </wd:Media_Reference>
                          <wd:Learning_Course_Lesson_Title>Course Evaluation - vILT (L1)</wd:Learning_Course_Lesson_Title>
                          <wd:Provide_Course_Grade>0</wd:Provide_Course_Grade>
                      </wd:Media_Lesson_Data>
                  </wd:Course_Lesson_Data>
              </wd:Learning_Course_Data>
          </wd:Learning_Course>
                    </AllCourses>
       <Offerings>
        <Offering>
            <Lesson>
                <Offering-ID>C2212001 DL 3Wks Mon 4pm-7pm EASTERN</Offering-ID>
                <Course-Number>00151744</Course-Number>
                 <Webinar>Y</Webinar>
                <Title>Launch Class Link - HDU_VILT01 - 1</Title>
                 <Facilitator-LDAP>AXH4006</Facilitator-LDAP>
                  <Webinar-URL>https://hdu.adobeconnect.com</Webinar-URL>
                  <Location/> 
                <Room>Ottawa District Training Center</Room>
            </Lesson>
            <Lesson>
                <Offering-ID>C2212001 DL 3Wks Mon 4pm-7pm EASTERN</Offering-ID>
                <Course-Number>00151744</Course-Number>
                 <Webinar>Y</Webinar>
                <Title>Launch Class Link - HDU_VILT01 - 3</Title>
                 <Facilitator-LDAP></Facilitator-LDAP>
                  <Webinar-URL>https://hdu.adobeconnect.com</Webinar-URL>
                <Location>7070</Location> 
                <Room>Ottawa District Training </Room>
            </Lesson>
            
        </Offering>
           <Offering>
               
               <Lesson>
                   <Offering-ID>00170024CA - 2022 Group 12 - Thurs 10AM-1PM EST</Offering-ID>
                   <Course-Number>00170024CA</Course-Number>
                    <Webinar>Y</Webinar>
                   <Title>Session 4</Title>
                                    <Facilitator-LDAP>TXB786</Facilitator-LDAP>
                                      <Webinar-URL>https://hdu-canada.adobeconnect.com/design_basics_2/</Webinar-URL>
                   <Location>Laval</Location> 
                   <Room/>
               </Lesson>
               <Lesson>
                   <Offering-ID>00170024CA - 2022 Group 12 - Thurs 10AM-1PM EST</Offering-ID>
                   <Course-Number>00170024CA</Course-Number>
                     <Webinar>Y</Webinar>
                   <Title>Session 5</Title>
                   <Facilitator-LDAP>ZXF99S</Facilitator-LDAP>
                      <Webinar-URL>https://hdu-canada.adobeconnect.com/design_basics_2/</Webinar-URL>
                   <Location>Laval</Location> 
                   <Room/>
               </Lesson>
           </Offering>
         
            </Offerings>
</FileAndCourses>

My xslt

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl=http://www.w3.org/1999/XSL/Transform
    xmlns:xs=http://www.w3.org/2001/XMLSchema
    xmlns:map=http://www.w3.org/2005/xpath-functions/map
    xmlns:wd="urn:com.workday/bsvc"
    exclude-result-prefixes="#all"
    expand-text="yes"
    version="3.0">
        <xsl:output method="xml" indent="yes"/>
        <xsl:accumulator name="learning-course-id" as="xs:string?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:ID/text()" select="string()"/>
    </xsl:accumulator>
    
    <xsl:accumulator name="lesson-mandatory" as="xs:boolean?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data" select="false()"/>
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Make_Lesson_Mandatory/text()" select=". = 1"/>
    </xsl:accumulator>
        <xsl:accumulator name="webinars" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Instructor_Led_Webinar_Lesson_Data[accumulator-before('lesson-mandatory')]/wd:Title/text()" 
            select="let $id := accumulator-before('learning-course-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>
        <xsl:accumulator name="classroom-lessons" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Instructor_Led_Lesson_Data[accumulator-before('lesson-mandatory')]/wd:Title/text()" 
            select="let $id := accumulator-before('learning-course-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>
        <xsl:accumulator name="offered-lesson-id" as="xs:string?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="Offerings/Offering/Lesson/Course-Number/text()" select="string()"/>
    </xsl:accumulator>
        <xsl:accumulator name="offered-lessons" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="Offerings/Offering" select="map{}"/>
        <xsl:accumulator-rule match="Offerings/Offering/Lesson/Title/text()" 
            select="let $id := accumulator-before('offered-lesson-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>
        <xsl:mode on-no-match="shallow-copy" use-accumulators="#all" streamable="yes"/>
        <xsl:output method="xml" indent="yes"/>
        <xsl:template match="/FileAndCourses" expand-text="yes">
        <OfferingsWithCourse>
            <xsl:apply-templates select="Offerings/Offering"/>
        </OfferingsWithCourse>
    </xsl:template>
    
    <xsl:template match="Offering">
        <xsl:copy>
            <xsl:apply-templates/>
            <xsl:variable name="webinars" select="accumulator-after('webinars')"/>
            <xsl:variable name="offered-lessons" select="accumulator-after('offered-lessons')"/>
            <xsl:for-each select="map:keys(accumulator-after('webinars'))[. = map:keys($offered-lessons)]">
                <xsl:variable name="webinar-id" select="."/>
                <xsl:for-each select="$webinars(.)[not(. = $offered-lessons($webinar-id))]">
                    <Error>No matching required lesson found for title {.} in Course num {$webinar-id}</Error>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
        <xsl:template match="Lesson">
        <xsl:apply-templates select="copy-of()" mode="grounded"/>
    </xsl:template>
    <xsl:template match="Offering/Lesson">
        <xsl:apply-templates select="copy-of()" mode="grounded"/>
    </xsl:template>
        <xsl:mode name="grounded" on-no-match="shallow-copy"/>
        <xsl:template mode="grounded" match="Lesson">
        <xsl:copy>
            <xsl:apply-templates/>
            <xsl:if test="Course-Number = ''">
                <Error>
                    <xsl:text>Missing required field Course Number. </xsl:text>                                    
                </Error>
            </xsl:if>                         
            <xsl:if test="Facilitator-LDAP = ''">
                <Error>
                    <xsl:text>Missing required field Facilitator LDAP for at least one of the lessons in the offering. </xsl:text>                                    
                </Error>
            </xsl:if> 
        </xsl:copy>
    </xsl:template>
      
    
    </xsl:template>     
</xsl:stylesheet> 

Actual output - Mapping logic not built

Expected output 1.)Need to map the Facilitator-LDAP with Instructor id and also validate it is a valid instructor i.e WorkdayUserName should have Instructor id in the Instructor node 2.)Need to map Location/rooms and validate if it is not valid . this is not required field (i.e) need to map internal value for a external value

<?xml version="1.0" encoding="UTF-8"?>
<OfferingsWithCourse xmlns:map="http://www.w3.org/2005/xpath-functions/map"
                     xmlns:wd="urn:com.workday/bsvc"
                     xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
   <Offering>
      <Lesson>
         <Offering-ID>C2212001 DL 3Wks Mon 4pm-7pm EASTERN</Offering-ID>
         <Course-Number>00151744</Course-Number>
         <Webinar>Y</Webinar>
         <Title>Launch Class Link - HDU_VILT01 - 1</Title>
         <Facilitator-LDAP>AXH4006</Facilitator-LDAP>
         <Webinar-URL>https://hdu.adobeconnect.com</Webinar-URL>
         <Location/>
         <Room>Ottawa District Training Center</Room>
         <InstructorID>119417764</InstructorID>
         <MappedLocation/>
         <MappedRoom>LOCATION-6-3881</MappedRoom>
      </Lesson>
      <Lesson>
         <Offering-ID>C2212001 DL 3Wks Mon 4pm-7pm EASTERN</Offering-ID>
         <Course-Number>00151744</Course-Number>
         <Webinar>Y</Webinar>
         <Title>Launch Class Link - HDU_VILT01 - 3</Title>
         <Facilitator-LDAP/>
         <Webinar-URL>https://hdu.adobeconnect.com</Webinar-URL>
         <Location>7070</Location>
         <Room>Ottawa District Training </Room>
         <InstructorID/>
         <MappedLocation/>
         <MappedRoom/>
         <Error>Missing required field Facilitator LDAP for at least one of the lessons in the offering. </Error>
         <Error>Mapped location not found for 7070. </Error>
         <Error>Mapped room not found for Ottawa District Training . </Error>
      </Lesson>
   </Offering>
   <Offering>
      <Lesson>
         <Offering-ID>00170024CA - 2022 Group 12 - Thurs 10AM-1PM EST</Offering-ID>
         <Course-Number>00170024CA</Course-Number>
         <Webinar>Y</Webinar>
         <Title>Session 4</Title>
         <Facilitator-LDAP>TXB786</Facilitator-LDAP>
         <Webinar-URL>https://hdu-canada.adobeconnect.com/design_basics_2/</Webinar-URL>
         <Location>Laval</Location>
         <Room/>
         <InstructorID>713400041</InstructorID>
         <MappedLocation>7070</MappedLocation>
         <MappedRoom/>
      </Lesson>
      <Lesson>
         <Offering-ID>00170024CA - 2022 Group 12 - Thurs 10AM-1PM EST</Offering-ID>
         <Course-Number>00170024CA</Course-Number>
         <Webinar>Y</Webinar>
         <Title>Session 5</Title>
         <Facilitator-LDAP>ZXF99S</Facilitator-LDAP>
         <Webinar-URL>https://hdu-canada.adobeconnect.com/design_basics_2/</Webinar-URL>
         <Location>Laval</Location>
         <Room/>
         <InstructorID/>
         <MappedLocation>7070</MappedLocation>
         <MappedRoom/>
         <Error>Instructor ID not found for Workday account ZXF99S. </Error>
      </Lesson>
   </Offering>
</OfferingsWithCourse>

CodePudding user response:

Here is an example setting up two more accumulators to create a map of location external values to internal values plus two templates to use that accumulator map later on to output a mapped location or an error for a Lesson:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:map="http://www.w3.org/2005/xpath-functions/map"
    xmlns:wd="urn:com.workday/bsvc"
    exclude-result-prefixes="#all"
    expand-text="yes"
    version="3.0">
        
    <xsl:output method="xml" indent="yes"/>

    <xsl:accumulator name="location-internal-value" as="xs:string?" initial-value="()" streamable="yes">
      <xsl:accumulator-rule match="Maps/Locations/Location" select="()"/>
      <xsl:accumulator-rule match="Maps/Locations/Location/InternalValue/text()" select="."/>
    </xsl:accumulator>

    <xsl:accumulator name="location-map" as="map(xs:string, xs:string)" initial-value="map{}" streamable="yes">
      <xsl:accumulator-rule match="Maps/Locations" select="map{}"/>
      <xsl:accumulator-rule match="Maps/Locations/Location/ExternalValue/text()" 
        select="map:put($value, string(), accumulator-before('location-internal-value'))"/>
    </xsl:accumulator>

    <xsl:accumulator name="learning-course-id" as="xs:string?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:ID/text()" select="string()"/>
    </xsl:accumulator>
    
    <xsl:accumulator name="lesson-mandatory" as="xs:boolean?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data" select="false()"/>
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Make_Lesson_Mandatory/text()" select=". = 1"/>
    </xsl:accumulator>

    <xsl:accumulator name="webinars" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Instructor_Led_Webinar_Lesson_Data[accumulator-before('lesson-mandatory')]/wd:Title/text()" 
            select="let $id := accumulator-before('learning-course-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>
        <xsl:accumulator name="classroom-lessons" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="AllCourses/wd:Learning_Course/wd:Learning_Course_Data/wd:Course_Lesson_Data/wd:Instructor_Led_Lesson_Data[accumulator-before('lesson-mandatory')]/wd:Title/text()" 
            select="let $id := accumulator-before('learning-course-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>
        
    <xsl:accumulator name="offered-lesson-id" as="xs:string?" initial-value="()" streamable="yes">
        <xsl:accumulator-rule match="Offerings/Offering/Lesson/Course-Number/text()" select="string()"/>
    </xsl:accumulator>
        <xsl:accumulator name="offered-lessons" as="map(xs:string, xs:string*)" initial-value="map{}" streamable="yes">
        <xsl:accumulator-rule match="Offerings/Offering" select="map{}"/>
        <xsl:accumulator-rule match="Offerings/Offering/Lesson/Title/text()" 
            select="let $id := accumulator-before('offered-lesson-id')
            return
            if (map:contains($value, $id))
            then map:put($value, $id, ($value($id), string()))
            else map:put($value, $id, string())"/>
    </xsl:accumulator>

    <xsl:mode on-no-match="shallow-copy" use-accumulators="#all" streamable="yes"/>
        
    <xsl:output method="xml" indent="yes"/>
        
    <xsl:template match="/FileAndCourses" expand-text="yes">
        <OfferingsWithCourse>
            <xsl:apply-templates select="Offerings/Offering"/>
        </OfferingsWithCourse>
    </xsl:template>
    
    <xsl:template match="Offering">
        <xsl:copy>
            <xsl:apply-templates/>
            <xsl:variable name="webinars" select="accumulator-after('webinars')"/>
            <xsl:variable name="offered-lessons" select="accumulator-after('offered-lessons')"/>
            <xsl:for-each select="map:keys(accumulator-after('webinars'))[. = map:keys($offered-lessons)]">
                <xsl:variable name="webinar-id" select="."/>
                <xsl:for-each select="$webinars(.)[not(. = $offered-lessons($webinar-id))]">
                    <Error>No matching required lesson found for title {.} in Course num {$webinar-id}</Error>
                </xsl:for-each>
            </xsl:for-each>
        </xsl:copy>
    </xsl:template>
        
    <xsl:template match="Lesson">
        <xsl:apply-templates select="copy-of()" mode="grounded"/>
    </xsl:template>

    <xsl:template match="Offering/Lesson">
        <xsl:apply-templates select="copy-of()" mode="grounded"/>
    </xsl:template>

    <xsl:mode name="grounded" on-no-match="shallow-copy"/>
        
    <xsl:template mode="grounded" match="Lesson">
        <xsl:copy>
            <xsl:apply-templates mode="#current"/>
            <xsl:if test="Course-Number = ''">
                <Error>
                    <xsl:text>Missing required field Course Number. </xsl:text>                                    
                </Error>
            </xsl:if>                         
            <xsl:if test="Facilitator-LDAP = ''">
                <Error>
                    <xsl:text>Missing required field Facilitator LDAP for at least one of the lessons in the offering. </xsl:text>                                    
                </Error>
            </xsl:if> 
        </xsl:copy>
    </xsl:template>

    <xsl:template mode="grounded" match="Lesson/Location[normalize-space() and not(map:contains(accumulator-before('location-map'), string()))]">
       <xsl:next-match/>
       <Error>Mapped location not found for {.}</Error>
    </xsl:template>

    <xsl:template mode="grounded" match="Lesson/Location[normalize-space() and map:contains(accumulator-before('location-map'), string())]">
       <xsl:next-match/>
       <MappedLocation>{accumulator-before('location-map')(.)}</MappedLocation>
    </xsl:template>
      
</xsl:stylesheet> 
  • Related