Subject: [xsl] xsl:key containing mixed elements From: George James <GeorgeJ@xxxxxxxxxxxxxxx> Date: Sat, 23 Oct 2004 13:10:04 +0100 |
Hi I have a problem that I'm trying to solve using <xsl:key> but I'm not getting the results that I expected. It's probably best to explain first what I want to do and then show how I tried to use <xsl:key> to solve the problem. I have a file containing a mixture of <UML:SimpleState> and <UML:CompositeState> elements. Each one has a name attribute, but in the case of the <UML:CompositeState> element the name comprises of a state name followed by a colon followed by a sub-machine state name. What I want to do is simply read my file and report any duplicate state names. So, here's a simplified example of some of the data in my file: <UML:SimpleState name="on" /> <UML:SimpleState name="off" /> <UML:SimpleState name="off" /> <UML:SimpleState name="standby" /> <UML:CompositeState name="rewind:rewinding" /> <UML:CompositeState name="forward:fastforwarding" /> <UML:CompositeState name="standby:waiting" /> <UML:CompositeState name="record:recording" /> <UML:CompositeState name="record:recording" /> I'd like to generate error messages for states 'off', 'standby' and 'record' because they are duplicates. This is how I tried to solve the problem. It works for the 'off' case but not for the 'standby' or the 'record' cases: <!-- Create an index containing the name of all simple states and the first part of the name of all composite states --> <xsl:key name="name" match="UML:CompositeState[@name]" use="substring-before(@name,':')" /> <xsl:key name="name" match="UML:SimpleState[@name]" use="@name" /> <xsl:template match='/'> <xsl:for-each select="//UML:CompositeState[@name]"> <xsl:variable name='name' select="substring-before(@name,':')"/> <xsl:if test="count(key('name',$name))>1"> <xsl:message>Duplicate state name: <xsl:value-of select='$name'/></xsl:message> </xsl:if> </xsl:for-each> <xsl:for-each select="//UML:SimpleState[@name]"> <xsl:variable name='name' select="@name"/> <xsl:if test="count(key('name',$name))>1"> <xsl:message>Duplicate state name: <xsl:value-of select='$name'/></xsl:message> </xsl:if> </xsl:for-each> </xsl:template> Can anyone enlighten me please? BTW I'm using xalan: Vendor: Apache Software Foundation Vendor URL: http://xml.apache.org/xalan-j D:\s>java -version java version "1.4.2_05" Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.2_05-b04) Java HotSpot(TM) Client VM (build 1.4.2_05-b04, mixed mode) Regards George George James Software Cachi Tools, Training, Technology www.georgejames.com +44-1932-252568
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] RSS, Joe Fawcett | Thread | Re: [xsl] xsl:key containing mixed , Jeni Tennison |
Re: [xsl] RSS, Joe Fawcett | Date | Re: [xsl] XSLT 2.0 *and* XSLT 1.0 v, Jeni Tennison |
Month |