Subject: Re: [xsl] Reading Attributes in XSL From: Jon Gorman <jonathan.gorman@xxxxxxxxx> Date: Tue, 15 Nov 2005 14:03:08 -0600 |
> > 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Reading Attributes in XSL, Haarman, Michael | Thread | [xsl] Writing results across the ne, Colin Paul Adams |
RE: [xsl] Reading Attributes in XSL, Haarman, Michael | Date | Re[2]: [xsl] Ouput escaping / XPath, Manuel Baehnisch |
Month |