Solved

How can I add blank lines/linefeeds using xslt?

Posted on 2001-08-08
6
279 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
LVL 4

Accepted Solution

by:
sdussinger earned 100 total points
Comment Utility
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
Comment Utility
Steve,

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

Regards, JimP  
0
 
LVL 4

Expert Comment

by:sdussinger
Comment Utility
Glad I could help....
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

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…
The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

771 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

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now