Subject: RE: [xsl] Using <xsl:for-each> and position() to increase indent in each iteration (includes XSLT 2.0 solution) From: "David Gadd" <David.Gadd@xxxxxxxxxxxxxxxxxxx> Date: Fri, 13 May 2005 14:24:59 -0700 |
Thanks to everyone for your feedback on this, this is very helpful! David Gadd -----Original Message----- From: Jay Bryant [mailto:jay@xxxxxxxxxxxx] Sent: Thursday, May 12, 2005 9:05 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] Using <xsl:for-each> and position() to increase indent in each iteration (includes XSLT 2.0 solution) Hi, David, I've done similar things in FO thus: <fo:block text-indent="{(position() - 1 ) * .25}in"><xsl:apply-templates/></fo:block> If you're not set on spaces for indentation, you could try: <p style="text-indent: {(position() -1) * .25}in"><xsl:apply-templates/></p> or (if you're defining styles somewhere): <p class="indent{(position() -1)}"><xsl:apply-templates/></p> If you are set on spaces, Aron's recursive template works for XSLT 1.0+. If you can do XSLT 2.0, you can use the "x to y" feature of for-each to get the spaces, thus: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="x"> <html> <body> <xsl:for-each select="y"> <p> <xsl:if test="position() > 1"> <xsl:for-each select="1 to (position() - 1)">   </xsl:for-each> </xsl:if> <xsl:value-of select="."/> </p> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet> Tested with Saxon 8. Jay Bryant Bryant Communication Services ----- Original Message ----- From: "David Gadd" <David.Gadd@xxxxxxxxxxxxxxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Thursday, May 12, 2005 6:47 PM Subject: [xsl] Using <xsl:for-each> and position() to increase indent in each iteration Hi, I'm new to the list and fairly new to XSL. I am wanting to use the position() function to increase the indent in an <xsl:for-each> iteration by 3 spaces, using the following logic, but preferably without using a case statement: position() == 1 > generate "" position() == 2 > generate " " position() == 3 > generate " " position() == 4 > generate " " etc etc As a separate issue, when I use in my xsl template it seems to fail (the disappears). By googling I found a suggestion to use   instead. Is there a reason why is not working? Thanks very much, David Gadd
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Question about the key() , omprakash . v | Thread | [xsl] Re: xsl-list Digest 13 May 20, Shivani Goel |
[xsl] Question about the key() func, aspsa | Date | RE: [xsl] Question about the key() , Michael Kay |
Month |