Solved

How can I add blank lines/linefeeds using xslt?

Posted on 2001-08-08
6
300 Views
Last Modified: 2008-01-09
Hello XML Experts!

With the following code snip I am attempting to do this:

Divide up a series of lines into 10 lines per section.  The last section will usually have a lesser number of lines--as it has whatever is left.

I need to add blank lines to the final section so it has the same number of lines (in size) as the others do.  It is hard to explain why, but it is how I have to do it to get the correct placement.

Everything seems to be working in the logic that I have, but I can't get the final part---actually making the linefeed happen, work.

This is what I have:

  <xsl:call-template name ="lastpage">
  <xsl:with-param name="count" select="(last() mod 10)"/>
  </xsl:call-template>


  <xsl:template name="lastpage">
  <xsl:param name="count"/>

  <xsl:if test="position()=last() and last() div 10 != 0">
  <xsl:for-each select="$count">
  **For each select = $count (could be any number between
    1 and 9) I need to have a linefeed but I am not sure
    how to make this work.**

  </xsl:for-each>
  </xsl:if>
  </xsl:template>

Any comments or suggestions would be appreciated.

JimP
0
Comment
Question by:JimP
  • 4
  • 2
6 Comments
 
LVL 4

Expert Comment

by:sdussinger
ID: 6366767
In your for-each:

<xsl:for-each select="$count">
  <xsl:text>&#10;</xsl:text>
</xsl:for-each>

This should put a blank line into the output.

--Steve
0
 

Author Comment

by:JimP
ID: 6366834
Thanks for your quick reply.

I tried this approach this afternoon (and again now) and received the following error message:

"Reference to variable or parameter 'count' must evaluate to a node list."

Am I missing something?

JimP

0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6366930
Well, this is a different problem. I assumed from your original post that you had count already set up from some other portion of your transform.

Post your XSL and XML files and I'll see if I can come up with something...

--Steve
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 4

Accepted Solution

by:
sdussinger earned 100 total points
ID: 6366969
That's what happens when you try and do these things at 2:00AM. You miss seeing what's in the original post...

I missed the fact that you set count to an integer earlier in the post.

So, the basic problem here is that for-each operates over a list of nodes, not a range of integers. There is no looping construct analagous to the for loop in standard programming languages. However, there is still a way to do this. It is a little messy, but it will work:

<xsl:template name="add-blank-lines">

  <xsl:param name="val" select="0"/>

  <xsl:if test="$val > 1">
    <xsl:call-template name="add-blank-lines">
      <xsl:with-param name="val" select="$val - 1"/>
    </xsl:call-template>
  </xsl:if>

  <xsl:text>&#10;</xsl:text>

</xsl:template>

This template will get called to add a series of blank lines.

Where you had the <xsl:for-each select="$count"> stuff, you'd put something like:

<xsl:call-template name="add-blank-lines">
  <xsl:with-param name="val" select="$count"/>
</xsl:call-template>

assuming that count has been initialized with the number of blank lines you want.

Ahh, the joys of recursion...

Hope this helps...

--Steve
0
 

Author Comment

by:JimP
ID: 6374408
Steve,

Recursion!  This worked.  Thanks for your help.  I was really stuck on that one.

Regards, JimP  
0
 
LVL 4

Expert Comment

by:sdussinger
ID: 6374624
Glad I could help....
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
installing and using WTP plugin eclipse MARS 3 111
Get the parent node - XMLTYPE 9 70
XML XSLT If loop 4 25
SQL XML ALL Nodes Compare in function 2 25
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question