xsl-list
[Top] [All Lists]

[xsl] PARAMS and VARIABLES in XSL

2007-01-30 12:42:12
I need help with the following problem.

This is the XML is wish to transform:
 
<clause>
 <sound time="1.2">
 <word>the</word>
 <word>quick</word>
 <sound time="2.2">
 <word>fox</word>
 <sound time="2.8">
 <word>jumped</word>
</clause>
<clause>
</clause>
 
I need to transform it into the following xml, where
the sound tags time attritubes are soundtime
attributes of the following word tags:
 
<clause>
 <word soundtime="1.2">the</word>
 <word soundtime="1.2">quick</word>
 <word soundtime="2.2">fox</word>
 <word soundtime="2.8">jumped</word>
</clause>
<clause>
</clause>
 
Note that the soundtime attribute should not change if
there was no intervening new sound tag. 
 
I have tried all sorts of solutions using axes,
preceding-sibling, but these did not work, since the
<word> and <sound> are not true siblings to the
processor, even though they are on the same level of
the hierarchy.
 
The solution I would like to work with is the
following, using params to accumulate the soundtime
variable. However, even with all the research I have
done, I cannot find a solution that the processor does
not error on. Can anyone help?
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; >
<xsl:template match="//clause/*">
<xsl:param name="soundtime" />
<xsl:if test="local-name() = 'sound'">
<xsl:param name="soundtime" select="@time" />
</xsl:if>
<xsl:if test="local-name() = 'word'">
<word sound = "{$soundtime}" >
<xsl:value-of select="." /> 
</word>
</xsl:if>
</xsl:template>
</xsl:stylesheet>



 
____________________________________________________________________________________
Cheap talk?
Check out Yahoo! Messenger's low PC-to-Phone call rates.
http://voice.yahoo.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>
--~--