Solved

How can I add blank lines/linefeeds using xslt?

Posted on 2001-08-08
6
322 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
Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

 
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

Technology Partners: 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

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
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…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

705 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