[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

How to get attribute values after comparing attributes

Subject: How to get attribute values after comparing attributes of two nodes ??
From: Dipesh Khakhkhar <dkhakhkh@xxxxxxxxxxxxxxx>
Date: Tue, 26 Aug 2003 14:05:50 -0400
xsl get attribute value
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"/>
<!-- Getting AeXDataExtract node with maximum attributes -->
<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]"/>
<!-- Getting Resource_Type node with maximum attributes -->
<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]"/>
<!-- Getting Resource node with maximum attributes -->
<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]"/>
<!-- Getting Identification node with maximum childnodes i.e. having maximum 
columns-->
<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]"/>
<!-- Getting Client_Agent node with maximum childnodes i.e. having maximum 
columns-->
<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]"/>
<!-- Outputting Column Header first and Then Data -->
<xsl:template match="/">
<!-- Printing header for AeXDataExtract -->
<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>
<!-- Printing header for resource type -->
<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>
<!-- Printing header for resource -->
<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>
<!-- Printing header for Inventory and Asset Tables -->
<xsl:text>INVENTORYID,RESOURCE.GUID,INVENTORYID,ASSETID,NAME,</xsl:text>
<!-- Printing header for IDENTIFICATION -->
<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>
<!-- Now putting data data below the Column Headers -->
<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">
<!-- THIS IS WORKING FINE -->
<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]/@*">
<!-- Not able to write proper syntax for this -->
<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


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.