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

Re: xsl for parsing strange xml

Subject: Re: xsl for parsing strange xml
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Mon, 23 Sep 2002 16:57:21 +0100
x parse get element name
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

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.