何时/否则无法按预期工作(Microsoft Visual Studio)

时间:2015-09-03 15:58:26

标签: xslt-1.0

我一直在努力按照我想要的方式格式化输出,但我不经常使用xsl。

这需要生成一个表,只有在名为' Active'的节点中有值时才会提取信息。但是当没有名为“计数许可证”的数据或价值时它应该通过调用模板放入一个空白字段。

它确实创建了该字段,但不仅仅是在“计算许可证”的情况下。条目不存在。我哪里出错?

感谢您的时间。

这是XSLT:

<?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"
                              xmlns:exsl="http://exslt.org/common">

  <xsl:output method="html" encoding="utf-8" indent="yes"/>
  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr>
            <td>
              <strong>User</strong>
            </td>
            <td>
              <strong>Counted License</strong>
            </td>
          </tr>
          <tr style="text-align:center;font-seize:8px;">
            <xsl:for-each select="registry/k/k/k/k/k/k/k/k/k">
              <xsl:for-each select="k">
                <xsl:if test="@name='UserInfo'">
                  <xsl:for-each select="k">
                    <xsl:for-each select="v">
                      <xsl:choose>
                        <xsl:when test="@name='Active'">
                          <tr style="text-align:center;font-seize:8px;">
                            <td><xsl:value-of select="../@name"/></td>
                            <xsl:for-each select="../v">
                              <xsl:choose>
                                <xsl:when test="@name='Counted Licenses'">
                                  <td><xsl:value-of select="@value"/></td>
                                </xsl:when>
                                <xsl:when test="@name='snCreated' or @name='snModified'">
                                  <!-- DO NOTHING -->
                                </xsl:when>
                                <xsl:otherwise>
                                  <!-- CREATE BLANK FIELD -->
                                <xsl:call-template name="blank" />
                                </xsl:otherwise>
                              </xsl:choose>
                            </xsl:for-each>
                          </tr>
                        </xsl:when>
                      </xsl:choose>
                    </xsl:for-each>
                  </xsl:for-each>
                </xsl:if>
              </xsl:for-each>
            </xsl:for-each>
          </tr>
        </table>
      </body>
    </html>
  </xsl:template>

  <xsl:template match="green" name="blank">
    <td>blank&#160;</td>

  </xsl:template>
</xsl:stylesheet>

这是XML:

<?xml version="1.0" encoding="utf-8"?>
<registry>
  <k name="HKEY_LOCAL_MACHINE">
    <k name="SOFTWARE">
      <k name="Interactive Intelligence">
        <k name="EIC">
          <k name="Directory Services">
            <k name="Root">
              <k name="CustomerSite">
                <k name="Production">
                  <k name="AdminConfig">
                    <v name="snCreated" value="0x00000006 (6)" type="REG_DWORD" />
                    <v name="snModified" value="0x01434cf0 (21187824)" type="REG_DWORD" />
                    <k name="StationInfo">
                      <v name="snCreated" value="0x00000007 (7)" type="REG_DWORD" />
                      <v name="snModified" value="0x01434cf2 (21187826)" type="REG_DWORD" />
                      <k name="00a95557-c3f6-4c45-b2b8-ebc56c0d00f6">
                        <v name="snCreated" value="0x00000008 (8)" type="REG_DWORD" />
                        <v name="snModified" value="0x00000008 (8)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x00000009 (9)" type="REG_DWORD" />
                          <v name="snModified" value="0x00000009 (9)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="01b01517-8743-4219-9535-20dd37600ee5">
                        <v name="snCreated" value="0x0000000a (10)" type="REG_DWORD" />
                        <v name="snModified" value="0x0000000a (10)" type="REG_DWORD" />
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000000b (11)" type="REG_DWORD" />
                          <v name="snModified" value="0x0000000b (11)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="06e2a817-7399-417a-b462-6c0b5cf3baee">
                        <v name="snCreated" value="0x0000000c (12)" type="REG_DWORD" />
                        <v name="snModified" value="0x0000000c (12)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000000d (13)" type="REG_DWORD" />
                          <v name="snModified" value="0x0000000d (13)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="NLISM002">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_LICENSE_BASIC_STATION" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x0000032e (814)" type="REG_DWORD" />
                        <v name="snModified" value="0x0000032e (814)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000032f (815)" type="REG_DWORD" />
                          <v name="snModified" value="0x0000032f (815)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="NLISM003">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_LICENSE_BASIC_STATION" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x00000330 (816)" type="REG_DWORD" />
                        <v name="snModified" value="0x00000330 (816)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x00000331 (817)" type="REG_DWORD" />
                          <v name="snModified" value="0x00000331 (817)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="PHGSM311">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_LICENSE_BASIC_STATION" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x012da8c6 (19769542)" type="REG_DWORD" />
                        <v name="snModified" value="0x012dab55 (19770197)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x012da8c7 (19769543)" type="REG_DWORD" />
                          <v name="snModified" value="0x012dab56 (19770198)" type="REG_DWORD" />
                        </k>
                      </k>
                    </k>
                    <k name="UserInfo">
                      <v name="snCreated" value="0x0000046c (1132)" type="REG_DWORD" />
                      <v name="snModified" value="0x01434cf1 (21187825)" type="REG_DWORD" />
                      <k name="User.A">
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x005c21b8 (6037944)" type="REG_DWORD" />
                        <v name="snModified" value="0x005c2223 (6038051)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x005c21b9 (6037945)" type="REG_DWORD" />
                          <v name="snModified" value="0x005c2224 (6038052)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="Test_USER_2">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_DIALER_SUPERVISOR_PLUGIN I3_ACCESS_HISTORICAL_REPORT_SUPERVISOR_PLUGIN I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER I3_ACCESS_WORKGROUP_SUPERVISOR_PLUGIN" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x00ec87e0 (15501280)" type="REG_DWORD" />
                        <v name="snModified" value="0x00ec8862 (15501410)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x00ec87e1 (15501281)" type="REG_DWORD" />
                          <v name="snModified" value="0x00ec8863 (15501411)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="User.B">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x00000957 (2391)" type="REG_DWORD" />
                        <v name="snModified" value="0x008cf75b (9238363)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x00000958 (2392)" type="REG_DWORD" />
                          <v name="snModified" value="0x008cf75c (9238364)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="User_John">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_DIALER_SUPERVISOR_PLUGIN I3_ACCESS_HISTORICAL_REPORT_SUPERVISOR_PLUGIN I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER I3_ACCESS_REPORT_ASSISTANT_SUPERVISOR_PLUGIN I3_ACCESS_WORKGROUP_SUPERVISOR_PLUGIN" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x00000959 (2393)" type="REG_DWORD" />
                        <v name="snModified" value="0x013e612f (20865327)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000095a (2394)" type="REG_DWORD" />
                          <v name="snModified" value="0x013e6130 (20865328)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="Test_USER_1">
                        <v name="Active" value="No" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x0000095b (2395)" type="REG_DWORD" />
                        <v name="snModified" value="0x008c0239 (9175609)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000095c (2396)" type="REG_DWORD" />
                          <v name="snModified" value="0x008c0238 (9175608)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="Theodora.User">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x0000095d (2397)" type="REG_DWORD" />
                        <v name="snModified" value="0x008cf75d (9238365)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x0000095e (2398)" type="REG_DWORD" />
                          <v name="snModified" value="0x008cf75e (9238366)" type="REG_DWORD" />
                        </k>
                      </k>
                      <k name="Thomas.Tank">
                        <v name="Active" value="Yes" type="REG_MULTI_SZ" />
                        <v name="Counted Licenses" value="I3_ACCESS_ACD_MEDIA_3_PLUS I3_ACCESS_CLIENT I3_ACCESS_DIALER_ADDON I3_ACCESS_INTERACTION_SCRIPTER_ADDON I3_ACCESS_RECORDER" type="REG_MULTI_SZ" />
                        <v name="snCreated" value="0x0000095f (2399)" type="REG_DWORD" />
                        <v name="snModified" value="0x0000095f (2399)" type="REG_DWORD" />
                        <k name="Qualifiers">
                          <v name="snCreated" value="0x00000960 (2400)" type="REG_DWORD" />
                          <v name="snModified" value="0x00000960 (2400)" type="REG_DWORD" />
                        </k>
                      </k>
                    </k>
                  </k>
                </k>
              </k>
            </k>
          </k>
        </k>
      </k>
    </k>
  </k>
</registry>

在收到的输出和预期的屏幕截图下面:

enter image description here

1 个答案:

答案 0 :(得分:1)

嗯,这是一个快速修复

                            <xsl:when test="@name='snCreated' or @name='snModified' or @name='Active'">
                              <!-- DO NOTHING -->
                            </xsl:when>

但是这个电子表格可以更好地重写。

更新:

上述解决方案不会产生空白,因为您没有“计数许可证”以外的值。

这是一个更新的电子表格,有点简化。

<?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"
                              xmlns:exsl="http://exslt.org/common">

  <xsl:output method="html" encoding="utf-8" indent="yes"/>
  <xsl:template match="/">
    <html>
      <body>
        <table border="1">
          <tr>
            <td>
              <strong>User</strong>
            </td>
            <td>
              <strong>Counted License</strong>
            </td>
          </tr>
          <tr style="text-align:center;font-seize:8px;">
            <xsl:for-each select="registry/k/k/k/k/k/k/k/k/k/k[@name='UserInfo']/k[v/@name='Active']">
              <tr style="text-align:center;font-seize:8px;">
                <td><xsl:value-of select="@name"/></td>
                <td>
                  <xsl:choose>
                    <xsl:when test="v/@name='Counted Licenses'">
                      <xsl:value-of select="v[@name='Counted Licenses']/@value"/>
                    </xsl:when>
                    <xsl:otherwise>
                      <xsl:text>blank&#160;</xsl:text>
                    </xsl:otherwise>
                  </xsl:choose>
                </td>
              </tr>
            </xsl:for-each>
          </tr>
        </table>
      </body>
    </html>
  </xsl:template>
</xsl:stylesheet>