1

以下是我需要转换的原始 XML 文件。作为输出,我需要显示每个触发器每个小部件的可用动画效果。就像 Widet 类型全部和触发器类型显示我需要的所有效果,如 1、3、6、9。

 <?xml version="1.0" encoding="utf-8"?>
<InputAnimationConfigurationSchema>
<ConfigurationEffects>
<AEffect Id="1" DisplayName="A Effect">
</AEffect>
<BEffect Id="2" DisplayName="B Effect">
</BEffect>
<CEffect Id="3" DisplayName="C Effect">
</CEffect>
<DEffect Id="4" DisplayName="D effect">
</DEffect>
<EEffect Id="5" DisplayName="E effect">
</EEffect>
<FEffect Id="6" DisplayName="F effect">
</FEffect>
<GEffect Id="7" DisplayName="G effect">
</GEffect>
<HEffect Id="8" DisplayName="H effect">
</HEffect>
<IEffect Id="9" DisplayName="I effect">
</IEffect>
<JEffect Id="10" DisplayName="J effect">
</JEffect>
<KEffect Id="11" DisplayName="K effect">
</HEffect>
<LEffect Id="12" DisplayName="L effect">
</KEffect>
</ConfigurationEffects>
<ConfigurationMappings>
<ConfigurationMap>
<Widget Type="All" Include="true" NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Show" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
</ConfigurationMap>
<ConfigurationMap>
<Widget Type="All" Include="true" NeedsMandatoryEffectConfiguration="true"/>
<Trigger Type="Hide" />
<ConfigurationEffects>
<Effect>1</Effect>
<Effect>2</Effect>
<Effect>3</Effect>
<Effect>9</Effect>
</ConfigurationEffects>
 </ConfigurationMap>
 <ConfigurationMap>
  <Widget Type="PlaceHolder" Include="false" NeedsMandatoryEffectConfiguration="true"/>
 </ConfigurationMap>
 <ConfigurationMap>
  <Widget Type="PosterItem" Include="false" NeedsMandatoryEffectConfiguration="true"/>
 </ConfigurationMap>
 </ConfigurationMappings>
 </InputAnimationConfigurationSchema>

我得到以下格式的输出:

All        Show     A Effect
--------------------------
All        Show     C Effect
--------------------------
All        Show     F Effect
-------------------------
All        Show     I Effect
----------------------------
All        Hide     A Effect
---------------------------
All        Hide     C Effect
--------------------------
All        Hide     F Effect
----------------------------

但我想以以下格式显示输出:

All        Show     A Effect
--------------------------
All        Show     C Effect
--------------------------
All        Show     F Effect
-------------------------
All        Show     I Effect
----------------------------
All        Hide     A Effect
---------------------------
All        Hide     C Effect
--------------------------
All        Hide     F Effect
----------------------------

PlaceHolder ---------------------------- 海报项目


我正在寻找的是,如果小部件不包含任何触发器和效果,那么它们也应该显示带有空值的小部件。如果有人能给我一些执行此任务的指示,将不胜感激

stuartLC 给出的 xsl 代码是我开始工作的基础,但为了显示占位符和后项而卡在这里

4

2 回答 2

1

看来您需要从顶部查找效果ConfigurationEffectsxsl:key是为这种类型的工作而设计的。请注意,因为元素似乎*Effect具有不同的名称,所以我已经使用*并在@Id. 我添加了一个$effectId变量以使其更清晰,但请注意,这并不是真正必要的。

您还应该考虑将for-each循环替换为apply-template

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
   <xsl:key name="effectLookup" match="/InputAnimationConfigurationSchema/ConfigurationEffects/*" use="@Id" />
   <xsl:template match="/">
      <html>
         <body>
            <h2></h2>
            <table border="1">
               <tr bgcolor="#9acd32">
                  <th>Widget</th>
                  <th>Trigger</th>
                  <th>effects</th>
               </tr>
               <xsl:for-each select="/InputAnimationConfigurationSchema/ConfigurationMappings/ConfigurationMap">
                  <xsl:variable name="widgetType">
                     <xsl:value-of select="Widget/@Type"/>
                  </xsl:variable>
                  <xsl:variable name="triggerType">
                     <xsl:value-of select="Trigger/@Type"/>
                  </xsl:variable>
                  <xsl:for-each select="ConfigurationEffects/Effect">
                     <xsl:variable name="effectId">
                        <xsl:value-of select="./text()"/>
                     </xsl:variable>
                     <tr>
                        <td>
                           <xsl:value-of select="$widgetType"/>
                        </td>
                        <td>
                           <xsl:value-of select="$triggerType"/>
                        </td>
                        <td>
                           <xsl:value-of select="key('effectLookup', $effectId)/@DisplayName" />
                        </td>
                     </tr>
                  </xsl:for-each>

               </xsl:for-each>
            </table>
         </body>
      </html>
   </xsl:template>
</xsl:stylesheet>

输出

<html>
  <body>
    <h2></h2>
    <table border="1">
      <tr bgcolor="#9acd32">
        <th>Widget</th>
        <th>Trigger</th>
        <th>effects</th>
      </tr>
      <tr>
        <td>All</td>
        <td>Show</td>
        <td>A Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Show</td>
        <td>B Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Show</td>
        <td>C Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Show</td>
        <td>I effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Hide</td>
        <td>A Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Hide</td>
        <td>B Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Hide</td>
        <td>C Effect</td>
      </tr>
      <tr>
        <td>All</td>
        <td>Hide</td>
        <td>I effect</td>
      </tr>
    </table>
  </body>
</html>
于 2013-06-18T07:57:20.817 回答
0

这很容易通过更改一行来实现。

改变:

 <td><xsl:value-of select="."/></td>

至:

<td>
    <xsl:value-of select="//ConfigurationEffects/*[@DisplayName][@Id= current()/.]/@DisplayName"/>
</td>
于 2013-06-18T08:11:01.670 回答