xsl-list
[Top] [All Lists]

Re: [xsl] XSL and XML Help

2006-10-13 06:29:38
Cho, Minho wrote:
I do need the for loop because my xml file has more then one set of
infobject.

That's what template matching is all about. For-loops are a usage from imperative languages, whereas XSLT more like a functional one. Using a template match will 'call' that template automagically each time the processor encounters a node that fits the specification in the match-attribute.

Thus, instead of using for-each, you could best use the example from Richard. It will save you from a lot of xsl:if and xsl:choose branches (also procedural heritage)

I GOT IT !! :-) <xsl:for-each select="//infoObject"> <tr> <td> <xsl:value-of select="infoObjectDetail[(_at_)title ='Description']"/>
<xsl:text>&#160;</xsl:text>
</td>
</tr>
  </xsl:for-each>

This will select ALL infoObjects, at any level, however deep and is an expensive operation. Better do it so:

<xsl:apply-templates select="infoObject/infoObjectDetail[(_at_)title='Description']" />

<xsl:template match="infoObjectDetail">
<tr> <td> <xsl:value-of select="."/>
   <xsl:text>&#160;</xsl:text>
   </td>
</tr>
</xsl:template>

Or like this, if you have more of this type of matches, you can specify it more precisely at template level:

<tr> <td> <xsl:apply-templates select="infoObject/infoObjectDetail" />
   </td>
</tr>

<xsl:template match="infoObjectDetail[(_at_)title='Description]">
   <xsl:value-of select="."/>
   <xsl:text>&#160;</xsl:text>
</xsl:template>

<xsl:template match="infoObjectDetail[(_at_)title!='Description]">
   NO DESCRIPTOIN FOUND!
</xsl:template>


Of course, if you insist, you can always stick to the for-each loop.

Cheers
-- Abel

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