Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2003, 01:14 PM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to get attribute values after comparing attrib

Hi,

I have two problems

1)
In my xml i found out a node with maximum attribute. Now there are many nodes with the same name either with the same number of attributes or less number of attributes as compared to the node with the maximum number of attributes.

Now i need to output data accordingly i.e. when attribute name in the processing node is same as the attribute node in the maximum attribute node then output the value else a seperator is outputted.
(The situation is depicted by the RESOURCE node in the following xml)


Below is my xml:
================

<?xml version="1.0" encoding="UTF-8"?>
<AEXDATAEXTRACT DTD_VERSION="2.2" EXTRACT_START_DATETIME="1/9/2003 4:49:39 PM" EXTRACT_TYPE="FULL" EXTRACT_COLLECTION="">
<RESOURCE_TYPE GUID="{493435f7-3b17-4c4c-b07f-c23e7ab7781f}" NAME="Computer" DESCRIPTION="Asset Type definition for Computer" SOURCE="Asset" CREATED_DATE="7/16/2002 5:22:23 PM" MODIFIED_DATE="9/23/2002 2:17:48 PM" DELETED="0">
<RESOURCE GUID="{C116FCBF-5B94-4F15-BF95-5795DBD384CD}" NAME="ALTIRISTEST_CPQ" SOURCE="" SITE_CODE="756win" DOMAIN="FIDD" SYSTEM_TYPE="Win32" OS_NAME="Microsoft Windows XP" OS_TYPE="Professional" OS_VERSION="5.1" OS_REVISION="Service Pack 1" LAST_LOGON_USER="" LAST_LOGON_DOMAIN="">
<INVENTORY>
<ASSET>
<IDENTIFICATION>
<ATTRIBUTE NAME="Name">ALTIRISTEST_CPQ</ATTRIBUTE>
<ATTRIBUTE NAME="Domain">FIDDOMRTLSLC</ATTRIBUTE>
<ATTRIBUTE NAME="Altkey1" NULL="FALSE" />
<ATTRIBUTE NAME="Altkey2">00-02-A5-1A-67-A6</ATTRIBUTE>
</IDENTIFICATION>
<CLASS NAME="Client_Agent">
<OBJECT>
<ATTRIBUTE NAME="Agent Name">Altiris eXpress NS Client</ATTRIBUTE>
<ATTRIBUTE NAME="Product Version">5.5.0.517</ATTRIBUTE>
<ATTRIBUTE NAME="Build Number">517</ATTRIBUTE>
<ATTRIBUTE NAME="Install Path">C:\Program Files\Altiris\eXpress\NS Client</ATTRIBUTE>
</OBJECT>
<OBJECT>
<ATTRIBUTE NAME="Agent Name">Altiris eXpress Inventory Solution</ATTRIBUTE>
<ATTRIBUTE NAME="Product Version">5.5.0.424</ATTRIBUTE>
<ATTRIBUTE NAME="Build Number">424</ATTRIBUTE>
<ATTRIBUTE NAME="Install Path">C:\Program Files\Altiris\eXpress\NS Client\Software Delivery\Software Packages\{01B54EB5-3679-4C73-9E10-E169D5A5EC59}</ATTRIBUTE>
</OBJECT>
</CLASS>
<CLASS NAME="Inventory_Results">
<OBJECT>
<ATTRIBUTE NAME="Collection Time">1/9/2003 3:06:56 AM</ATTRIBUTE>
<ATTRIBUTE NAME="File Count">3</ATTRIBUTE>
<ATTRIBUTE NAME="Total Size">139271</ATTRIBUTE>
<ATTRIBUTE NAME="Version">5: 5: 0: 423</ATTRIBUTE>
</OBJECT>
</CLASS>
</ASSET>
</INVENTORY>
</RESOURCE>
<RESOURCE GUID="{C116FCBF-5B94-4F15-BF95-5795DBD384CD}" NAME="ALTIRISTEST_CPQ" SOURCE="" SITE_CODE="756win" DOMAIN="FIDD" SYSTEM_TYPE="Win32" OS_NAME="Microsoft Windows XP" OS_TYPE="Professional" OS_VERSION="5.1" OS_REVISION="Service Pack 1" LAST_LOGON_USER="" LAST_LOGON_DOMAIN="" AdditionalCol="Additional Col Value">
<INVENTORY>
<ASSET>
<IDENTIFICATION>
<ATTRIBUTE NAME="Name">ALTIRISTEST_CPQ</ATTRIBUTE>
<ATTRIBUTE NAME="Additional Column">additional column value</ATTRIBUTE>
<ATTRIBUTE NAME="Domain">FIDDOMRTLSLC</ATTRIBUTE>
<ATTRIBUTE NAME="Altkey1" NULL="FALSE" />
<ATTRIBUTE NAME="Altkey2">00-02-A5-1A-67-A6</ATTRIBUTE>
</IDENTIFICATION>

<CLASS NAME="Client_Agent">
<OBJECT>
<ATTRIBUTE NAME="Agent Name">Altiris eXpress NS Client</ATTRIBUTE>
<ATTRIBUTE NAME="Product Version">5.5.0.517</ATTRIBUTE>
<ATTRIBUTE NAME="Extra Column">Extra COlumn Value1</ATTRIBUTE>
<ATTRIBUTE NAME="Build Number">517</ATTRIBUTE>
<ATTRIBUTE NAME="Install Path">C:\Program Files\Altiris\eXpress\NS Client</ATTRIBUTE>
</OBJECT>
</CLASS>
</ASSET>
</INVENTORY>
</RESOURCE>
</RESOURCE_TYPE>
</AEXDATAEXTRACT>

---------------------------------------------------------------------

XSL
===

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>

<xsl:variable name="mostattForAexDataExtract">
<xsl:for-each select="//AEXDATAEXTRACT">
<xsl:sort select="count(attribute::*)"
order="descending" data-type="number"/>
<xsl:if test="position()=1">
<xsl:value-of select="generate-id()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxAttADE-node" select="//node()[generate-id() = $mostattForAexDataExtract]"/>

<xsl:variable name="mostattForResourceType">
<xsl:for-each select="//RESOURCE_TYPE">
<xsl:sort select="count(attribute::*)"
order="descending" data-type="number"/>
<xsl:if test="position()=1">
<xsl:value-of select="generate-id()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxAttResType-node" select="//node()[generate-id() = $mostattForResourceType]"/>

<xsl:variable name="mostattForResource">
<xsl:for-each select="//RESOURCE">
<xsl:sort select="count(attribute::*)"
order="descending" data-type="number"/>
<xsl:if test="position()=1">
<xsl:value-of select="generate-id()"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxAttResource-node" select="//node()[generate-id() = $mostattForResource]"/>

<xsl:variable name="mostattIdentification">
<xsl:for-each select="//IDENTIFICATION">
<xsl:sort select="count(ATTRIBUTE)" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="generate-id(.)"/>
</xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxAttIdentification-node" select="//node()[generate-id() = $mostattIdentification]"/>

<xsl:variable name="mostattClientAgentTable">
<xsl:for-each select="//CLASS">
<xsl:choose>
<xsl:when test="normalize-space(@NAME)='Client_Agent'">
<xsl:for-each select="OBJECT">
<xsl:sort select="count(ATTRIBUTE)" order="descending"/>
<xsl:if test="position()=1">
<xsl:value-of select="generate-id(..)"/>
</xsl:if>
</xsl:for-each>
</xsl:when>
</xsl:choose>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="maxattClntAgt-node" select="//node()[generate-id() = $mostattClientAgentTable]"/>

<xsl:template match="/">

<xsl:text>DATE,</xsl:text>
<xsl:for-each select="//node()[generate-id() = $mostattForAexDataExtract]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>

<xsl:text>SEQUENCEID,RESOURCE_TYPE.</xsl:text>
<xsl:for-each select="//node()[generate-id() = $mostattForResourceType]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>

<xsl:text>RESOURCE_TYPE.GUID,RESOURCE.</xsl:text>
<xsl:for-each select="//node()[generate-id() = $mostattForResource]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>

<xsl:text>INVENTORYID,RESOURCE.GUID,INVENTORYID,AS SETID,NAME,</xsl:text>

<xsl:text>IDENTIFICATIONID,ASSETID,</xsl:text>
<xsl:for-each select="//node()[generate-id() = $mostattIdentification]">
<xsl:for-each select="ATTRIBUTE/@NAME">
<xsl:value-of select="."/>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
</xsl:for-each>
<!-- Printing header for CLIENT_AGENT <xsl:for-each select="//node()[generate-id() = $mostattIdentification]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each> -->
<!-- Printing header for Active_Directory_Details <xsl:for-each select="//node()[generate-id() = $mostattIdentification]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each> -->
<!-- Printing header for User_Contact_Details
<xsl:for-each select="//node()[generate-id() = $mostattIdentification]/@*">
<xsl:value-of select="name(.)" ></xsl:value-of>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each> -->
<xsl:text>#10;</xsl:text>

<xsl:apply-templates select="//IDENTIFICATION"/>
<xsl:apply-templates select="//RESOURCE"/>
</xsl:template>

<xsl:template match="IDENTIFICATION">
<xsl:variable name="r" select="."/>
<xsl:for-each select="$maxAttIdentification-node/ATTRIBUTE">

<xsl:value-of select="normalize-space($r/ATTRIBUTE[@NAME=current()/@NAME])"/>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
<xsl:text>#10;</xsl:text>
</xsl:template>

<xsl:template match="RESOURCE">
<xsl:variable name="r" select="."/>
<xsl:for-each select="//node()[generate-id() = $mostattributes]/@*">

<xsl:value-of select="normalize-space($r/[@=current()/name(@)])"/>
<xsl:if test="position()!=last()">,</xsl:if>
</xsl:for-each>
<xsl:text>#10;</xsl:text>
</xsl:template>
</xsl:stylesheet>

---------------------------------------------------------------------

As shown above in the xsl, for the IDENTIFCATION node i am able to get the data properly. But not the attribtues.


2) I am not able to get any node for CLASS node having attribute NAME="Client_Agent".
As i see in the debugger, i am getting two generate id for the node CLASS ? What should i do to get the node CLASS having OBJECT node it it which contains maximum ATTRIBUTE node. This CLASS node should have attribute NAME="Client_Agent" ?


Please inform me how should i solve these two problems.

Eagerly waiting for reply.

Regards,
Dipesh Khakhkhar







Similar Threads
Thread Thread Starter Forum Replies Last Post
Comparing Two values from same table MArgente BOOK: Beginning SQL 3 December 11th, 2009 07:35 AM
Comparing nodes attribute(Michael Kay help meeee) sumapathy XSLT 4 August 25th, 2007 03:21 AM
Comparing values between different MSHFlexGrid davekrunal46 VB How-To 0 November 28th, 2005 07:41 AM
Comparing values between different MSHFlexGrid davekrunal46 VB Databases Basics 0 November 28th, 2005 07:39 AM
Access to attribute values from class of attribute jacob C# 1 October 28th, 2005 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.