[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Using <xsl:for-each> and position() to increase i
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: 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|