Solved

How can I add blank lines/linefeeds using xslt?

Posted on 2001-08-08
6
318 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
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. 
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

738 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