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

xsl:key containing mixed elements

Subject: xsl:key containing mixed elements
From: George James <GeorgeJ@xxxxxxxxxxxxxxx>
Date: Sat, 23 Oct 2004 13:10:04 +0100
xsl key use substring
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

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.