为XML Infopath表单生成XSLT

问题描述 投票:0回答:1

我需要有关将Infopath XML转换为XSLT的帮助,这对我来说非常具有挑战性。任何人都可以帮助我为下面的XML创建XSLT。这是一个Infopath表单,我需要帮助创建使用表单库创建的xml样式表。

我试图创建XSLT,但一切都进入了。

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

要求没有LOB PSStatus新的父NIPP PPC ak123 FA完成项目RNUR ATRev XX1528

这是我试过的

            <?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>
xml xslt infopath
1个回答
0
投票

正如我在对您的问题的评论中所说,您的输入不是格式良好的XML文档,XSLT无法处理。

如果您有一个格式良好的XML输入,例如:

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>

然后你可以使用:

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>

要得到:

结果

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

请注意xsl:stylesheet open标记中的命名空间处理。

© www.soinside.com 2019 - 2024. All rights reserved.