RE: [xsl] xsl:key containing mixed elements

Subject: RE: [xsl] xsl:key containing mixed elements
From: George James <GeorgeJ@xxxxxxxxxxxxxxx>
Date: Sun, 24 Oct 2004 17:06:22 +0100
Michael
Thank you for confirming that it works in other xsl processors.

For the record I've submitted this as a xalan bug:
http://issues.apache.org/bugzilla/show_bug.cgi?id=31868

Regards
George

George James Software
Cachi Tools, Training, Technology
www.georgejames.com
+44-1932-252568



> -----Original Message-----
> From: Michael Kay [mailto:mike@xxxxxxxxxxxx]
> Sent: 23 October 2004 16:28
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] xsl:key containing mixed elements
>
>
> Your code works fine in Saxon. It reports:
>
> Duplicate state name: standby
> Duplicate state name: record
> Duplicate state name: record
> Duplicate state name: off
> Duplicate state name: off
> Duplicate state name: standby
>
> Michael Kay
> http://www.saxonica.com/
>
>
> > -----Original Message-----
> > From: George James [mailto:GeorgeJ@xxxxxxxxxxxxxxx]
> > Sent: 23 October 2004 13:10
> > To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> > Subject: [xsl] xsl:key containing mixed elements
> >
> > 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