Wrox Programmer Forums
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 9th, 2005, 01:50 PM
Registered User
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Regex

Is it possible to use regular expression to assign 1000 zeros or spaces to a variable?

It's for padding using the following
<xsl:value-of select="substring( concat(Element2Pad,$Spaces) , 1, 500 )"/>

Thank you in advance.

 
Old May 9th, 2005, 03:47 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure how you would expect a regular expression to help with this.

In XSLT 2.0 you can write

<xsl:variable name="$spaces" select="
  string-join(for $i in 1 to 1000 return ' ', '')"/>

In 1.0 you can do

<xsl:template name="replicate">
  <xsl:param name="s"/>
  <xsl:param name="i"/>
  <xsl:for-each select="(//node())[position() &lt;= $i]">
    <xsl:value-of select="$s"/>
  </xsl:for-each>
</xsl:template>

<xsl:variable name="spaces">
  <xsl:call-template name="replicate">
    <xsl:with-param name="s" select="' '"/>
    <xsl:with-param name="i" select="50"/>
  </xsl:call-template>
</xsl:variable>

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 18th, 2005, 09:21 AM
Registered User
 
Join Date: Apr 2005
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi MhKay,

Thank you for the solution. The code you provided works beautifully and more elegant than <xsl:variable name="Spaces" select="' ...'"/>

Again string-join(for $i in 1 to 1000 return 'Thank you '.
;)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Regex pendemv JSP Basics 4 December 8th, 2008 08:29 AM
regex mrame XSLT 12 July 25th, 2008 09:37 AM
More regex help Snib Pro PHP 4 December 16th, 2004 09:56 PM
Need RegEx help Snib Pro PHP 6 November 16th, 2004 06:59 AM
Regex Help boyer99g General .NET 2 October 8th, 2004 05:46 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.