I am trying to get the node with maximum attributes.
This kind of thing is so much easier with XPath 2.0:
<xsl:variable name="nodes" select="...">
<xsl:variable name="max-atts"
select="max(for $n in $nodes return count($n/@*))"/>
<xsl:variable name="nodes-with-max-atts"
select="$nodes[count(@*) = $max-atts]"/>
This will all work with Saxon 7.x. If you have to use an XSLT 1.0
processor, you can simulate this logic using extension functions from
the EXSLT library or elsewhere.
Michael Kay
How do i
get that. Facing
problem with the usage of xs:variable since that can not be
change. I want to
get the attribute names in my first line of output.
I want to write something like this.
<!-- Defining Global variables -->
xsl:var name=colHeaderForTable1;
xsl:var name=maxColNoForTable1 select="number(0)"; <!--
Keeping maximum number
of attributes for the particular node as zero -->
xsl:for-each //Table1
xsl:var name=temp select ="count(no. of columns in this
table)"; <! --getting
column count for the current table -->
<!-- For the firt time this comparision will be true and in
the global
variable i will get names of the attribute name -->
if (temp > maxColNoForTable1)
colHeaderForTable1={"Somevalue", "Somevalue",Getting each
attribute name
followed by seperator}
</xsl:for-each>
<!-- In this way I want the names of the attributes for a
node having maximum
no. of attributes. The problem here is i can not change the
variable value, so
is there any other way to achieve the same. I have not
defined the variable
inside for loop since I would need that value in future
processing of my
document.
Below is the input.
Input
======
<?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_TYPE> </AEXDATAEXTRACT>
===================================================================
Seekin some help.
Eagerly waiting for reply. Appreciated.
Regards,
Dipesh
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list