[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

How can I add blank lines/linefeeds using xslt?

Posted on 2001-08-08
6
Medium Priority
?
332 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 4

Accepted Solution

by:
sdussinger earned 400 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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. 
Loops Section Overview
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses

872 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