Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: For Each to a Comma Separated List

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 10/22/2009 12:02:00 PM
Brian wrote:

> Here is the simple XML Block where I want to transform the ListNode items 
> into a comma separated list that gets inserted into a table cell.
> 
> <XMLBlk BlkAttr="A001">
> 	<NodeA>Standard</NodeA>
> 	<ListNode>
> 		<ListItem>Item 1</ListItem>
> 		<ListItem>Item 2</ListItem>
> 		<ListItem>Item 3</ListItem>
> 	</ListNode>
> 	<AnotherNode></AnotherNode>
> </XMLBlk>
> 
> The list output would be "Item 1, Item 2, Item 3"

With XSLT 2.0 creating the comma separated list is as easy as

   <xsl:template match="ListNode">
     <xsl:value-of select="ListItem" separator=", "/>
   </xsl:template>

With XSLT 1.0 you need

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

> My table is somehow creates the CSL but inserts the individual items into 
> what appears to be sub-cells.  I get word wrapping on the "Item 1" text 
> before it writes the "Item 2" text in the table cell.
> 
> Question...  what is the best way to structure this transform so that the 
> cell just gets a CSL and wraps the content if it exceeds the width of the 
> table cell?

What kind of output do you create with the XSLT? Is that HTML?


-- 

	Martin Honnen --- MVP XML
	http://msmvps.com/blogs/martin_honnen/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent