I'm having a hard time mapping your input to your output, but that being said,
you are certainly not "stuck with" your proposed solution. What you appear to
be stuck with is a hard time in giving up the procedural programming model
mind-set and letting yourself operate in the XSLT functional programming model.
Your input contains a <informaltable> with two <row> child elements. Each row
has two <entry> child elements.
Your output has a <table> root element with two <entry> child elements.
That's a total of four <entry> elements in the input that somehow map to two
<entry> elements in the output.
Please explain your production rule a little more clearly and you will surely
get a solution.
--
Charles Knell
cknell(_at_)onebox(_dot_)com - email
-----Original Message-----
From: Mathieu Malaterre <mathieu(_dot_)malaterre(_at_)gmail(_dot_)com>
Sent: Thu, 20 Sep 2007 14:52:27 +0200
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] variable outside a for-each loop
Hello,
this is clearly a question that has been asked many times on this
mailing list. But I simply cannot find anything smart to do for my
issue:
I have the following XML (docbook):
<informaltable>
<row>
<entry>
<para>ABC</para>
</entry>
<entry>
<para>DEF</para>
</entry>
</row>
<row>
<entry>
<para/>
</entry>
<entry>
<para>DEF 2</para>
</entry>
</row>
</informaltable>
My goal is to produce:
<table>
<entry one="ABC" two="DEF"/>
<entry one="ABC" two="DEF 2"/>
</table>
In C/C++ this is trivial at each step whenever row/entry is empty I
would use some local variable instead. But in XSL I am stuck with:
<xsl:for-each select="row">
<xsl:variable name="one"
select="normalize-space(string-join(entry[1]/para,' '))"/>
<xsl:variable name="two"
select="normalize-space(string-join(entry[2]/para,' '))"/>
<entry one="{$one}" two="{$two}"/>
</xsl:for-each>
Could someone please let me know what the correct solution is when using XSL ?
Thanks so much;
--
Mathieu
--~------------------------------------------------------------------
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>
--~--