RE: [xsl] Checking for nodes in other nodes

Subject: RE: [xsl] Checking for nodes in other nodes
From: "Aron Bock" <aronbock@xxxxxxxxxxx>
Date: Tue, 07 Jun 2005 16:28:40 +0000
Joe,

I'm making up some data to show something similar; it may be instructive to work/adapt it to your needs:

This input (note that machine-3 uses B twice):

<data>
   <enums>
       <enum>A</enum>
       <enum>B</enum>
   </enums>
   <machines>
       <machine name="machine-1">
           <value>A</value>
       </machine>
       <machine name="machine-2">
           <value>A</value>
       </machine>
       <machine name="machine-3">
           <value>B</value>
           <value>B</value>
       </machine>
   </machines>
</data>

And this XSL:

<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes"/>


<xsl:key match="machine" name="k-machines-per-enum" use="value"/>

   <xsl:template match="data">
       <xsl:copy>
           <xsl:apply-templates select="enums/enum"/>
       </xsl:copy>
   </xsl:template>

<xsl:template match="enum">
<enum value="{.}">
<xsl:attribute name="usecount">
<xsl:value-of select="count(key('k-machines-per-enum', .))"/>
</xsl:attribute>
</enum>
</xsl:template>


</xsl:stylesheet>

Yields this, each enum and the number of machines in which it is used:

<?xml version="1.0" encoding="UTF-8"?>
<data>
 <enum value="A" usecount="2"/>
 <enum value="B" usecount="1"/>
</data>


The idea, then, is that as you generate a common header with those enums whose usage count is greater than 1. Also, when you generate a specific C file, include those enums whose [unique] usage count, for that machine is 1.


Regards,

--A

From: "Simon, Jb" <jb.simon@xxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Checking for nodes in other nodes
Date: Tue, 07 Jun 2005 11:29:44 -0400



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.

_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE! http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/


Current Thread