xmlxsltinfopath

Generate XSLT for XML Infopath Form


I need help on converting Infopath XML to XSLT its very challenging for me to convert. Can anyone help me on creating XSLT for the below XML. This is an Infopath form i need help in creating Stylesheet for the xml which are created using the form library.

I tried to create XSLT but all gone in vein.

            <?xml version="1.0" encoding="utf-8"?>
            <?mso-infoPathSolution name="urn:schemas-microsoft-com:office:infopath:Project-Setup:-myXSD-2018-03-14T07-59-16" solutionVersion="1.0.0.1013" productVersion="15.0.0.0" PIVersion="1.0.0.0" ?>
            <?mso-application progid="InfoPath.Document" versionProgid="InfoPath.Document.3"?>
            <my:myFields>
                <my:RequestNo>ak123</my:RequestNo>
                <my:LOB>FA</my:LOB>
                <my:AreaFinMgr>

                <pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"><pc:DisplayName>FM</pc:DisplayName><pc:AccountId>i:0#.w|ad\fm</pc:AccountId><pc:AccountType>User</pc:AccountType></pc:Person></my:AreaFinMgr>
                <my:ProjMgr>

                <pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"><pc:DisplayName>NT</pc:DisplayName><pc:AccountId>i:0#.w|ad\nt</pc:AccountId><pc:AccountType>User</pc:AccountType></pc:Person></my:ProjMgr>
                <my:Approver>

                <pc:Person xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls"><pc:DisplayName>AT</pc:DisplayName><pc:AccountId>i:0#.w|ad\at</pc:AccountId><pc:AccountType>User</pc:AccountType></pc:Person></my:Approver>
                <my:InternalUse>
                    <my:PSStatus>Completed</my:PSStatus>
                    <my:PSComments></my:PSComments>
                    <my:PSby>
                        <pc:Person>
                            <pc:DisplayName>i:0#.w|ad\ga</pc:DisplayName>
                            <pc:AccountId></pc:AccountId>
                            <pc:AccountType></pc:AccountType>
                        </pc:Person>
                    </my:PSby>
                    <my:PSDate>2019-02-12</my:PSDate>
                    <my:Prod_by>
                        <pc:Person>
                            <pc:DisplayName>i:0#.w|ad\nr</pc:DisplayName>
                            <pc:AccountId></pc:AccountId>
                            <pc:AccountType></pc:AccountType>
                        </pc:Person>
                    </my:Prod_by>
                    <my:Prod_Date>2019-02-12</my:Prod_Date>
                </my:InternalUse>
                <my:Repeating>
                    <my:Item>
                        <my:RequestTYpe>1</my:RequestTYpe>
                        <my:RequestText>New Request</my:RequestText>
                        <my:NewSection>
                            <my:New>Project</my:New>
                            <my:Tier1>R</my:Tier1>
                            <my:Tier2>RAProj</my:Tier2>
                            <my:Tier3>RAMIn</my:Tier3>
                            <my:Tier4>RAM_N_P</my:Tier4>
                            <my:Tier5>RNUR</my:Tier5>
                            <my:Tier6></my:Tier6>
                            <my:Tier7></my:Tier7>
                            <my:Parent>RNUR</my:Parent>
                            <my:NIPP>ATRev</my:NIPP>
                            <my:PPC>XX1528</my:PPC>
                            <my:SpecialInstruction>Use project XX1528</my:SpecialInstruction>
                            <my:BudgetCode></my:BudgetCode>
                            <my:WorkType></my:WorkType>
                            <my:CAPPMLOB></my:CAPPMLOB>
                            <my:OpenTimeEntry></my:OpenTimeEntry>
                            <my:ClaritySpecialInst></my:ClaritySpecialInst>
                            <my:ITROI_StartDate xsi:nil="true"></my:ITROI_StartDate>
                            <my:ITROI_EndDate xsi:nil="true"></my:ITROI_EndDate>
                            <my:ITROI_Desc></my:ITROI_Desc>
                            <my:ITROI_RMC></my:ITROI_RMC>
                            <my:ITROI_IsProgIni>No</my:ITROI_IsProgIni>
                            <my:Temp1>
                                <pc:Person>
                                    <pc:DisplayName></pc:DisplayName>
                                    <pc:AccountId></pc:AccountId>
                                    <pc:AccountType></pc:AccountType>
                                </pc:Person>
                            </my:Temp1>
                            <my:Temp3></my:Temp3>
                            <my:Temp4>
                                <pc:Person>
                                    <pc:DisplayName></pc:DisplayName>
                                    <pc:AccountId></pc:AccountId>
                                    <pc:AccountType></pc:AccountType>
                                </pc:Person>
                            </my:Temp4>
                            <my:Temp5>
                                <pc:Person>
                                    <pc:DisplayName></pc:DisplayName>
                                    <pc:AccountId></pc:AccountId>
                                    <pc:AccountType></pc:AccountType>
                                </pc:Person>
                            </my:Temp5>
                            <my:field2></my:field2>
                            <my:EPMOVali>false</my:EPMOVali>
                            <my:Capitalization xsi:nil="true"></my:Capitalization>
                        </my:NewSection>
                        <my:DescChange>
                            <my:DescNew></my:DescNew>
                            <my:DescIPP></my:DescIPP>
                            <my:DescName></my:DescName>
                            <my:DescNewName></my:DescNewName>
                            <my:DescSpecial></my:DescSpecial>
                        </my:DescChange>
                        <my:Rollup>
                            <my:RollNew></my:RollNew>
                            <my:RollIPP></my:RollIPP>
                            <my:RollNewLoc></my:RollNewLoc>
                            <my:RollSpecial></my:RollSpecial>
                        </my:Rollup>
                    </my:Item>
                </my:Repeating>
                <my:ClickStatus>PPC_Created</my:ClickStatus>
                <my:listName>1</my:listName>
                <my:formName></my:formName>
                <my:ReasonForRequest>Projt</my:ReasonForRequest>
                <my:EPMO_Field>false</my:EPMO_Field>
                <my:LOB_PMO></my:LOB_PMO>
                <my:Billable>Yes</my:Billable>
            </my:myFields>

Request No LOB PSStatus New Parent NIPP PPC ak123 FA Completed Project RNUR ATRev XX1528

This is what i tried

            <?xml version="1.0" encoding="UTF-8"?>
            <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
            <xsl:template match="/">
            <html> 
            <body>
              <h2>My CD Collection</h2>
              <table border="1">
                <tr bgcolor="#9acd32">
                  <th style="text-align:left">Request No</th>
                  <th style="text-align:left">LOB</th>
                  <th style="text-align:left">PSStatus</th>
                  <th style="text-align:left">New Parent</th>
                  <th style="text-align:left">NIPP</th>
                  <th style="text-align:left">PPC</th>
                </tr>
                <xsl:for-each select="my:myFields/my:Repeating">
                <tr>
                  <td><xsl:value-of select="my:myFields/my:RequestNo" /></td>
                  <td><xsl:value-of select="my:myFields/my:LOB"/></td>
                  <td><xsl:value-of select="my:myFields/my:InternalUse/my:PSStatus"/></td>
                  <td><xsl:value-of select="my:myFields/my:Repeating/my:Item"/></td>
                  <td><xsl:value-of select="my:myFields/my:Repeating/my:Item/my:NIPP"/></td>
                  <td><xsl:value-of select="my:myFields/my:Repeating/my:Item/my:PPC"/></td>
                </tr>
                </xsl:for-each>
              </table>
            </body>
            </html>
            </xsl:template>
            </xsl:stylesheet>

Solution

  • As I said in a comment to your question, your input is not a well-formed XML document and cannot be processed by XSLT.

    If you had a well-formed XML input such as:

    XML

    <my:myFields xmlns:my="http://example.com/my" xmlns:pc="http://schemas.microsoft.com/office/infopath/2007/PartnerControls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <my:RequestNo>ak123</my:RequestNo>
      <my:LOB>FA</my:LOB>
      <my:AreaFinMgr>
        <pc:Person>
          <pc:DisplayName>FM</pc:DisplayName>
          <pc:AccountId>i:0#.w|ad\fm</pc:AccountId>
          <pc:AccountType>User</pc:AccountType>
        </pc:Person>
      </my:AreaFinMgr>
      <my:ProjMgr>
        <pc:Person>
          <pc:DisplayName>NT</pc:DisplayName>
          <pc:AccountId>i:0#.w|ad\nt</pc:AccountId>
          <pc:AccountType>User</pc:AccountType>
        </pc:Person>
      </my:ProjMgr>
      <my:Approver>
        <pc:Person>
          <pc:DisplayName>AT</pc:DisplayName>
          <pc:AccountId>i:0#.w|ad\at</pc:AccountId>
          <pc:AccountType>User</pc:AccountType>
        </pc:Person>
      </my:Approver>
      <my:InternalUse>
        <my:PSStatus>Completed</my:PSStatus>
        <my:PSComments/>
        <my:PSby>
          <pc:Person>
            <pc:DisplayName>i:0#.w|ad\ga</pc:DisplayName>
            <pc:AccountId/>
            <pc:AccountType/>
          </pc:Person>
        </my:PSby>
        <my:PSDate>2019-02-12</my:PSDate>
        <my:Prod_by>
          <pc:Person>
            <pc:DisplayName>i:0#.w|ad\nr</pc:DisplayName>
            <pc:AccountId/>
            <pc:AccountType/>
          </pc:Person>
        </my:Prod_by>
        <my:Prod_Date>2019-02-12</my:Prod_Date>
      </my:InternalUse>
      <my:Repeating>
        <my:Item>
          <my:RequestTYpe>1</my:RequestTYpe>
          <my:RequestText>New Request</my:RequestText>
          <my:NewSection>
            <my:New>Project</my:New>
            <my:Tier1>R</my:Tier1>
            <my:Tier2>RAProj</my:Tier2>
            <my:Tier3>RAMIn</my:Tier3>
            <my:Tier4>RAM_N_P</my:Tier4>
            <my:Tier5>RNUR</my:Tier5>
            <my:Tier6/>
            <my:Tier7/>
            <my:Parent>RNUR</my:Parent>
            <my:NIPP>ATRev</my:NIPP>
            <my:PPC>XX1528</my:PPC>
            <my:SpecialInstruction>Use project XX1528</my:SpecialInstruction>
            <my:BudgetCode/>
            <my:WorkType/>
            <my:CAPPMLOB/>
            <my:OpenTimeEntry/>
            <my:ClaritySpecialInst/>
            <my:ITROI_StartDate xsi:nil="true"/>
            <my:ITROI_EndDate xsi:nil="true"/>
            <my:ITROI_Desc/>
            <my:ITROI_RMC/>
            <my:ITROI_IsProgIni>No</my:ITROI_IsProgIni>
            <my:Temp1>
              <pc:Person>
                <pc:DisplayName/>
                <pc:AccountId/>
                <pc:AccountType/>
              </pc:Person>
            </my:Temp1>
            <my:Temp3/>
            <my:Temp4>
              <pc:Person>
                <pc:DisplayName/>
                <pc:AccountId/>
                <pc:AccountType/>
              </pc:Person>
            </my:Temp4>
            <my:Temp5>
              <pc:Person>
                <pc:DisplayName/>
                <pc:AccountId/>
                <pc:AccountType/>
              </pc:Person>
            </my:Temp5>
            <my:field2/>
            <my:EPMOVali>false</my:EPMOVali>
            <my:Capitalization xsi:nil="true"/>
          </my:NewSection>
          <my:DescChange>
            <my:DescNew/>
            <my:DescIPP/>
            <my:DescName/>
            <my:DescNewName/>
            <my:DescSpecial/>
          </my:DescChange>
          <my:Rollup>
            <my:RollNew/>
            <my:RollIPP/>
            <my:RollNewLoc/>
            <my:RollSpecial/>
          </my:Rollup>
        </my:Item>
      </my:Repeating>
      <my:ClickStatus>PPC_Created</my:ClickStatus>
      <my:listName>1</my:listName>
      <my:formName/>
      <my:ReasonForRequest>Projt</my:ReasonForRequest>
      <my:EPMO_Field>false</my:EPMO_Field>
      <my:LOB_PMO/>
      <my:Billable>Yes</my:Billable>
    </my:myFields>
    

    then you could use:

    XSLT 1.0

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:my="http://example.com/my"
    exclude-result-prefixes="my">
    <xsl:output method="html" encoding="utf-8"/>
    
    <xsl:template match="/">
        <html> 
            <body>
                <h2>put your own title here</h2>
                <table border="1">
                    <tr>
                    <th>Request No</th>
                    <th>LOB</th>
                    <th>PSStatus</th>
                    <th>New Parent</th>
                    <th>NIPP</th>
                    <th>PPC</th>
                </tr>
                <xsl:for-each select="my:myFields/my:Repeating">
                    <tr>
                        <td><xsl:value-of select="../my:RequestNo" /></td>
                        <td><xsl:value-of select="..//my:LOB"/></td>
                        <td><xsl:value-of select="../my:InternalUse/my:PSStatus"/></td>
                        <td><xsl:value-of select="my:Item/my:NewSection/my:New"/></td>
                        <td><xsl:value-of select="my:Item/my:NewSection/my:NIPP"/></td>
                        <td><xsl:value-of select="my:Item/my:NewSection/my:PPC"/></td>
                    </tr>
                </xsl:for-each>
                </table>
            </body>
        </html>
    </xsl:template>
    
    </xsl:stylesheet>
    

    to get:

    Result

    <html>
    <body>
    <h2>put your own title here</h2>
    <table border="1">
    <tr>
    <th>Request No</th>
    <th>LOB</th>
    <th>PSStatus</th>
    <th>New Parent</th>
    <th>NIPP</th>
    <th>PPC</th>
    </tr>
    <tr>
    <td>ak123</td>
    <td>FA</td>
    <td>Completed</td>
    <td>Project</td>
    <td>ATRev</td>
    <td>XX1528</td>
    </tr>
    </table>
    </body>
    </html>
    

    Note the namespace handling in the xsl:stylesheet open tag.