Hi,
You may want to try the following XSL. (Thanks to Bruce for
setting me on the right track).
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8" indent="yes"/>
<xsl:key name="equip" match="/Root/Equipment"
use="/Root/Equipment/Message/Field/EnumeratedType"/>
<xsl:template match="/Root">
<xsl:for-each select="/Root/EnumeratedType">
<xsl:variable name="var" select="Name"/>
<xsl:value-of select="count(key('equip', $var))"/>
</xsl:for-each>
</xsl:template>
<xsl:template match="/Root/Equipment">
<xsl:value-of select="."/>
</xsl:template>
</xsl:stylesheet>
My input XML:
<Root>
<EnumeratedType>
<Name>Speed Type</Name>
<Enumeration>
<Name>Low</Name>
<Value>1</Value>
</Enumeration>
<Enumeration>
<Name>Med</Name>
<Value>5</Value>
</Enumeration> <Enumeration>
<Name>High</Name>
<Value>8</Value>
</Enumeration>
</EnumeratedType>
<Equipment>
<Name>Motor</Name>
<Message>
<Name>Motor Speed</Name>
<Field>
<Name>MotorID</Name>
<DataType>integer</DataType>
</Field>
<Field>
<Name>Speed</Name >
<DataType>Enumerated Type</DataType>
<EnumeratedType>Speed Type</EnumeratedType>
</Field>
</Message>
</Equipment>
<Equipment>
<Name>Alternator</Name>
<Message>
<Name>Motor Speed</Name>
<Field>
<Name>MotorID</Name>
<DataType>integer</DataType>
</Field>
<Field>
<Name>Speed</Name >
<DataType>Enumerated Type</DataType>
<EnumeratedType>Speed Type</EnumeratedType>
</Field>
</Message>
</Equipment>
</Root>
The stylesheet correctly produced the output 2.
Cheers,
Omprakash.V
-----Original Message-----
From: Simon, Jb [mailto:jb(_dot_)simon(_at_)lmco(_dot_)com]
Sent: Tuesday, June 07, 2005 9:00 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Checking for nodes in other nodes
Given the following XML
<EnumeratedType>
<Name>Speed Type</Name>
<Enumeration>
<Name>Low</Name>
<Value>1</Value>
</Enumeration>
<Enumeration>
<Name>Med</Name>
<Value>5</Value>
</Enumeration> <Enumeration>
<Name>High</Name>
<Value>8</Value>
</Enumeration>
</EnumeratedType>
<Equipment>
<Name>Motor</Name>
<Message>
<Name>Motor Speed</Name>
<Field>
<Name>MotorID</Name>
<DataType>integer</DataType>
</Field>
<Field>
<Name>Speed<Name >
<DataType>Enumerated Type</DataType>
<EnumeratedType>Speed Type</EnumeratedType>
</Field>
</Message/
</Equipment>
What I need to be able to determine is if an enumerated type is used in
more than one equipment. (The XSL is used to generate C code, and each
equipment is generated to a different file. If the type is used in
multiple pieces of equipment then it should be generated to a
"common_types.h" file, if it is only used by ne piece of equipment then
it should be generated in that equipment's file)
Currently I can use the same .xsl to generate the different files, using
a command line parameter, however, all of the enumerated types are
generates to all files at this point. I'm pretty noob and cluless about
xslt, so I don't even know where to begin to attempt this part of the
task.
Thanks
Joe Simon
--------------------------------
This Sig Intentionally Left Blank
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--