I've been struggling getting the output formatted the way I want but I'm just not using xsl often enough.
This need to generate a table, it only extracts the information if there is a value in the node named 'Active' but when there is no data or value named 'Counted Licenses' it should put a blank field in by calling a template.
It does create that field but always and not only when the 'Counted Licenses' entry doesn't exist. Where do I go wrong?
Thanks for your time.
This is the 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 </td>
</xsl:template>
</xsl:stylesheet>
This is the 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>
below a screenshot from the output received and expected:
Well, this a quick fix
<xsl:when test="@name='snCreated' or @name='snModified' or @name='Active'">
<!-- DO NOTHING -->
</xsl:when>
However this spreadsheet could've been rewritten more nicely.
UPDATE:
The solution above does not produce blanks, because you don't have values other than "Counted Licenses".
This is an updated spreadsheet, a little simplified.
<?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 </xsl:text>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</xsl:for-each>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
User contributions licensed under CC BY-SA 3.0