Subject: Re: [xsl] xsl for parsing strange xml From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 23 Sep 2002 16:57:21 +0100 |
Hi Aparna, > How do I tackle this scenario to show html for Vehicle and Car > separately? I am using xsl to parse the xml and use <div> tags to > group things by class i.e. Class with its methods should be inside a > <div>, interface and its methods should be in a separate <div>. If I understand what you're doing correctly, it looks as though you want to group the <member> elements based on their 'name' attributes. Specifically, if a <member> element's 'name' begins with "M:" then you want it to be grouped together with the information about the <member> whose 'name' is the string before the '.', with a "T:" prefix rather than a "M:" prefix. For example, say that you were on the <member> element whose 'name' is "T:Car". You want to get all the <member> elements whose 'name', before the '.', is "M:Car". The easiest way to get hold of these elements is to set up a key in advance that indexes all the <member> elements whose 'name' begins with "M:" by the value of their 'name' attribute before the '.': <xsl:key name="methods" match="member[starts-with(@name, 'M:')]" use="substring-before(@name, '.')" /> Then you can use: key('methods', 'M:Car') to get all the methods that are related to the Car type. So given any <member> element representing a type, you can use this method to create and populate the <div> for the class: <xsl:template match="member[starts-with(@name, 'T:')]"> <xsl:variable name="name" select="substring-after(@name, 'T:')" /> <div> <h2><xsl:value-of select="$name" /></h2> <xsl:apply-templates select="summary" /> <h3>Methods</h3> <dl> <xsl:apply-templates select="key('methods', concat('M:', $name))" /> </dl> </div> </xsl:template> <xsl:template match="member[starts-with(@name, 'M:')]"> <xsl:variable name="name" select="substring-after(@name, '.')" /> <dt><xsl:value-of select="$name" /></dt> <dd> <xsl:apply-templates select="summary" /> </dd> </xsl:template> The only thing you have to worry about then is that you only apply templates to the <member> elements that represent types. If all the <member> elements are in a <members> element, for example, then you can do: <xsl:template match="members"> <xsl:apply-templates select="member[starts-with(@name, 'T:')]" /> </xsl:template> Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] xsl for parsing strange x, James Fuller | Thread | RE: [xsl] xsl for parsing strange x, Michael Kay |
RE: [xsl] xsl for parsing strange x, James Fuller | Date | RE: [xsl] xsl for parsing strange x, Passin,Thomas B. (To |
Month |