xsl-list
[Top] [All Lists]

Re: [xsl] I would like to know how I can do this

2011-02-24 14:09:57
How about:

    <xsl:variable name="city-names" select="'Toronto', 'London'"/>

or even (to make it easier to maintain the list):

    <xsl:variable name="cities" select="'Toronto,London'"/>
    <xsl:variable name="city-names" select="tokenize($cities, ',')"/>

then, instead of <temperature>...</temperature>:

    <xsl:variable name="pos" select="position()"/>
    <xsl:variable name="tag"
select="translate(normalize-space($city-names[$pos]), ' ', '-')"/>
    <xsl:element name="{$tag}">...</xsl:element>

This should even work if you decide to start tracking the weather in
New York. ;)

-Brandon :)


On Thu, Feb 24, 2011 at 2:47 PM,  <ycao5(_at_)scs(_dot_)carleton(_dot_)ca> 
wrote:

Hi,

My xslt stylesheet is going to convert a CSV file into XML format. The
format of the CSV
file is the following:

temperature1
temperature2

The output xml file will be the format of the following:

<Toronto> temperature1 </Toronto>
<London> temperature2 </London>

I am trying to use a static array to hold the city name: Toronto and London.
Would you
like to give me some suggestions on how I can do this by modifying the
following xslt
stylesheet?


<xsl:variable name="lines" as="xs:string*"
select="tokenize($input-text, '\r?\n')"/>

<xsl:variable name="parsed-lines">
<root>
<xsl:for-each select="$lines">
<xsl:variable name="tokenizedSample" select="tokenize(., ',')"/>
<xsl:if test="count($tokenizedSample) >= 1">
<temperature>
<xsl:value-of select="$tokenizedSample[1]"/>
</temperature>
</xsl:if>
</xsl:for-each>
</root>
</xsl:variable>

<xsl:template name="main">
<xsl:element name="file_header">
<xsl:copy-of select="$parsed-lines" />
</xsl:element>
</xsl:template>


thanks for any assistance,

Yang


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>