|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Newbie Question: Building Variables Based on Multiple El
jeffrod@xxxxxxxxxx wrote:
> Is there a way for me to build upon a variable string based on
> multiple elements of the same name?
Sure. An xsl:variable can be assigned the result of a 'select' or can
be used as a container for template instantiation. In the latter case,
you can roam around, generating any kind of output you want, and instead
of going directly into the result tree ("output") it goes into the
variable, which is then of type Result Tree Fragment (RTF). An RTF can
be used like a string, which is adequate for your purposes.
So, you can just do the following:
test.xml:
<test>
<elem>This</elem>
<elem>is</elem>
<elem>a</elem>
<elem>test</elem>
</test>
concat.xsl:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="elements">
<xsl:text>Value of $elements: </xsl:text>
<xsl:for-each select="/test/elem">
<xsl:value-of select="."/>
<xsl:if test="position() < last()">
<xsl:text> </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>.</xsl:text>
</xsl:variable>
<xsl:template match="/">
<xsl:value-of select="$elements"/>
</xsl:template>
</xsl:stylesheet>
---
Note that the elements don't have to have the same name here; you could
use the results of any 'select' that is legal within xsl:for-each.
Steve
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








