xsl-list
[Top] [All Lists]

Re: Merging nodes to process with FO

2005-08-30 04:00:28
Hi,

Tempore 05:14:49, die 08/30/2005 AD, hinc in 
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com scripsit Russell Levy 
<russlevy(_at_)rogers(_dot_)com>:

My problem is I can't do a for-each on either the unit or the occupant;
if I do it on the unit, I'll only get one row for unit 1, and if I do it
on the occupant, I won't get any rows for 2. I also want to be have it
sorted by unit, so I wouldn't be able to do a for-each on all occupants,
then another on all units that don't have an occupant.

Why don't you just nest the loops instead of putting them adjacent to each 
other?


Consider this little stysheet (change 'root' to a proper name) :

<xsl:stylesheet version="1.0"
     xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:output method="text"/>

<xsl:key name="occupant" match="occupant" use="unitid"/>

<xsl:template match="root">
<xsl:for-each select="unit">
        <xsl:variable name="unit" select="."/>
        <xsl:variable name="occupants" select="key('occupant',id)"/>
        <xsl:choose>
                <xsl:when test="$occupants">
                        <xsl:for-each select="$occupants">
                                <xsl:value-of select="$unit/name"/> | <xsl:value-of 
select="name"/>
                                <xsl:text>&#10;</xsl:text>
                        </xsl:for-each>
                </xsl:when>
                <xsl:otherwise>
                        <xsl:value-of select="$unit/name"/> | Vacant
                </xsl:otherwise>
        </xsl:choose>
</xsl:for-each>
</xsl:template>

</xsl:stylesheet>


regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
«Et ipsa scientia potestas est»  - Francis Bacon , Meditationes sacrae

--~------------------------------------------------------------------
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>