[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: Displaying column headers only if variable changes
Thanks, that worked perfectly. Only problem now is that if I have a "type" that doesn't have any diagrams on it, I still get the title for that type, like this: Class Diagrams Use Case Diagrams diagram 1 diagram 2 Activity Diagrams diagram 1 diagram 2 Sequence Diagrams Neither class nor sequence have any diagrams, but I still got the heading in the report. I guess that means ( I can't see the XML unfortunately), that its coming from the XML somehow. Any ideas of what I can do to get around this? Or any idea how I can output the xml so I can see what it looks like? Brian -----Original Message----- From: Joerg Heinicke [mailto:joerg.heinicke@xxxxxx] Sent: Monday, February 11, 2002 7:26 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: Displaying column headers only if variable changes Hi Brian, you have the "general" and well-known variable problem: You can not reassign the value of a variable. So your way is not possible. Even the preceding-sibling-axis can not be used, because you sort the values. So you have to use the "easiest" method ;-) 'Muenchian Method': You have to add a key to your stylesheet: <xsl:key name="elements" match="element" use="type"/> Later your for-each: <xsl:for-each select="element[count( . | key('elements', type)[1] ) = 1]"> Now you have selected all unique types: <xsl:value-of select="type"/> Now you can select all elements with this type: <xsl:for-each select="key('elements', type)"> <xsl:value-of select="Foundation.Core.ModelElement.name"/> </xsl:for-each> </xsl:for-each> Change 'element' to the name of the element you need. For more information on Grouping with Muenchian Method: http://www.jenitennison.com/xslt/grouping/muenchian.xml Regards, Joerg ----- Original Message ----- From: "Brian Burridge" <brian_burridge@xxxxxxxxxxxxx> To: <XSL-List@xxxxxxxxxxxxxxxxxxxxxx> Sent: Monday, February 11, 2002 7:05 PM Subject: Displaying column headers only if variable changes > > I have an xml list of diagrams. Each diagram has a type. I am sorting on that type with, > > <xsl:sort data-type="text" order="descending" case-order="upper-first" select="type"/> > <xsl:sort data-type="text" order="ascending" case-order="upper-first" select="Foundation.Core.ModelElement.name"/> > > This works fine. What I need to do now, however, is every time the type changes, print the type name. This would result in something like this: > > Activity > diagram 1 > diagram 2 > > Use Case > diagram 1 > diagram 2 > > Sequence > diagram 1 > diagram 2 > diagram 3 > > I set up a global variable called lastDiagramType, using this code: > <xsl:variable name="lastDiagramType">LAST</xsl:variable> > > And I'm checking it like this as I loop through in my for-each: > <xsl:if test="type != $lastDiagramType"> > <b><xsl:value-of select="type"/></b><br/> > <xsl:variable name="lastDiagramType"><xsl:value-of select="type"/></xsl:variable> > <b><xsl:value-of select="lastDiagramType"/></b><br/> > </xsl:if> > > Problem is, it doesn't set the "lastDiagramType" variable to the new type. As you see in the code, right now I'm printing what lastDiagramType is changed to, for debug purposes, and it never changes. It stays "LAST" as I default set it, but it is hitting that code. > > Any ideas? > > Brian N. Burridge > Sr. Internet Developer Analyst > The Internet Group @ Cox Target Media XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|