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

Re: Reading Attributes in XSL

Subject: Re: Reading Attributes in XSL
From: Jon Gorman <jonathan.gorman@xxxxxxxxx>
Date: Tue, 15 Nov 2005 14:03:08 -0600
xslt reading attributes
> > I cannot get this to work where it is needed to first read
> > the first attribute and then all attributes of the child and then
> > back to reading the second attribute of the parent element. Also how
> > to keep track of next items by restricting count of rows per
> > table to just
> > 4.
>
> You can get the elements in groups of four and restart your table or page
> based upon that easily enough, q.v. --
>
> http://www.dpawson.co.uk/xsl/sect2/N4486.html#d5052e727

As Mike mentions there are really two problems here, one is how to get
the info from the attributes and the second is a grouping problem.

Your second statement of the problem is much easier to read, but I'm
not really clear why you are going on the position of the attribute.
Does the code really need to be that generic?

Here's how I would approach your problem (I supposed I'm leaning more
for speed of implementation than anything else): parse out the data
based on attribute name, create an xml doc, use the xml doc to
generate the output you want via grouping.

In some more detail

1.) Create a template for the element that you're scraping the
attribute and child attributes from.

<xsl:template match="parent">
</xsl:template>

2.) In "real life" I would break this code down into more meaningful
semantic templates but for a quick solution we can just use value ofs.
 This will get the  foo attribute of the parent, then cycle through
the children, getting the foo and bar attribute for each, and finish
off with the bar attribute of the parent.  It's not recursive but by
modifying the middle it is pretty straightforward to make it so.

<xsl:template match="parent">
<row><xsl:value-of select="@foo" /></row>
<xsl:for-each select="*">
<xsl:for-each select="@*">
<row><xsl:value-of select="@foo"/> <xsl:value-of select="@bar /></row>
</xsl:for-each>
</xsl:for-each>
<row><xsl:value-of select="@bar" /></row>
</xsl:template>


3) I now have another stylesheet that would process the output of step
2. and have a grouping over the rows: ie something like
<xsl:stylesheet...
<xsl:template match="rows">
<xsl:for-each select="row[position() mod 4 = 1]">
<xsl:for-each select=". | following-sibling::row[position() <4]">
<xsl:value-of select="row" />
</xsl:for-each>
</xsl:for-each>
</xsl:template>


Covered in more detailed in the faq on grouping.

Of course, I'm a bit of an XSLT hobbyist, so there are probably better
solutions out there.

Jon Gorman

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.