Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 2nd, 2006, 07:04 AM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default concat function help!

Hi everybody! With the next XML code, I'd like to extract the content of each block element.

<main>
<parkway>
        â€¦
</parkway>
    <boulevard>
        <block> Panorama street </block>
        <block> Gold avenue </block>
        <block> Rodeo Plaza </block>
    <boulevard>

</main>

The problem is how to use the concat function to display the content of all block elements, for example:

“Panorama street, gold avenue, rodeo plaza”

Would be better a kind of template to apply it for different XML files with variable number of block elements? If I have an atribute in the boulevard element like the "numberofblocks", would be necessary to control an iteration or to know the number of commas to write? Thanks in advanced


 
Old May 2nd, 2006, 07:28 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In XSLT 2.0:

<xsl:template match="boulevard">
  <xsl:value-of select="string-join(block, ', ')"/>
</xsl:template>

In 1.0:

<xsl:template match="boulevard">
  <xsl:for-each select="block"/>
    <xsl:value-of select="."/>
    <xsl:if test="position() != last()">
      <xsl:text>, </xsl:text>
    </xsl:if>
  </xsl:for-each>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 2nd, 2006, 09:31 AM
Authorized User
 
Join Date: Apr 2006
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Michael ;)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Concat Help Needed pixelheart XSLT 6 August 5th, 2010 02:00 AM
How to do Very Large String Concat? EcceBozo XSLT 2 July 29th, 2008 03:58 PM
concat function for strings franta1346 Reporting Services 0 May 30th, 2007 06:47 AM
concat 2 different cursor sreekesh ADO.NET 0 August 18th, 2006 07:11 AM
concat problems gonesail XSLT 1 May 12th, 2004 08:19 PM





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